Nginx/rails - How do I make an api call from a webpack server on localhost to an external server?












0














I tried to setup a reverse proxy with nginx, and after the changes I made, the page where I view our json data for our api (www.ourapihost.com/issues.json) is now timing out with the error



We're sorry but something went wrong. If you are the application owner check the logs for more information.



However, the logs are blank. I had to clear them because it was taking too long to cat the logfile, but when I try to refresh the page, it keeps timing out with the above error, and it's not adding anything to the log.



This is our current nginx configuration:



server {
listen 80; #443 ssl http2;



server_name <our server domain>;
root /home/deployer/ft_parks/current/public;
access_log /var/log/nginx/wilderness-patrol.net_access.log;
# error_log /var/log/nginx/wilderness-patrol.net_error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
keepalive_timeout 200;

error_page 500 502 503 504 /500.html;

try_files $uri @app;

# include /etc/nginx/snippets/letsencrypt-acme-challenge.conf;

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
location @app {
proxy_pass http://wp_server;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;

# location /issues {
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# proxy_pass http://<my ip>:3001/;
# }

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
location ~* .(jpg|jpeg|gif|png|css|js|ico|xml|svg)$ {
access_log off;
log_not_found off;
expires 30d;
}
}

location = /500.html {
root /home/deployer/ft_parks/current/public;
}
}


The location /issues block that is commented out is the section I added to try and add the reverse proxy. My webpack server is running on localhost:3001.



I have read several other related posts here on stackoverflow about this issue, and have tried all of the solutions they suggested, but none of them worked for me. I feel like I'm either missing something in my location /issues block, or that I'm just simply not writing it properly. I have also already tryed using the rack-cors gem, which I couldn't get working either.



Any advice? Thanks!










share|improve this question






















  • did you check your nginx access & error logs?
    – Lenin Raj Rajasekaran
    Nov 21 at 3:20










  • I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
    – Austio
    Nov 21 at 3:43










  • Nothing mentioned in the question indicates any CORS-related problem
    – sideshowbarker
    Nov 21 at 6:23










  • Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
    – Elliot Tregoning
    Nov 22 at 12:44
















0














I tried to setup a reverse proxy with nginx, and after the changes I made, the page where I view our json data for our api (www.ourapihost.com/issues.json) is now timing out with the error



We're sorry but something went wrong. If you are the application owner check the logs for more information.



However, the logs are blank. I had to clear them because it was taking too long to cat the logfile, but when I try to refresh the page, it keeps timing out with the above error, and it's not adding anything to the log.



This is our current nginx configuration:



server {
listen 80; #443 ssl http2;



server_name <our server domain>;
root /home/deployer/ft_parks/current/public;
access_log /var/log/nginx/wilderness-patrol.net_access.log;
# error_log /var/log/nginx/wilderness-patrol.net_error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
keepalive_timeout 200;

error_page 500 502 503 504 /500.html;

try_files $uri @app;

# include /etc/nginx/snippets/letsencrypt-acme-challenge.conf;

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
location @app {
proxy_pass http://wp_server;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;

# location /issues {
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# proxy_pass http://<my ip>:3001/;
# }

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
location ~* .(jpg|jpeg|gif|png|css|js|ico|xml|svg)$ {
access_log off;
log_not_found off;
expires 30d;
}
}

location = /500.html {
root /home/deployer/ft_parks/current/public;
}
}


The location /issues block that is commented out is the section I added to try and add the reverse proxy. My webpack server is running on localhost:3001.



I have read several other related posts here on stackoverflow about this issue, and have tried all of the solutions they suggested, but none of them worked for me. I feel like I'm either missing something in my location /issues block, or that I'm just simply not writing it properly. I have also already tryed using the rack-cors gem, which I couldn't get working either.



Any advice? Thanks!










share|improve this question






















  • did you check your nginx access & error logs?
    – Lenin Raj Rajasekaran
    Nov 21 at 3:20










  • I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
    – Austio
    Nov 21 at 3:43










  • Nothing mentioned in the question indicates any CORS-related problem
    – sideshowbarker
    Nov 21 at 6:23










  • Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
    – Elliot Tregoning
    Nov 22 at 12:44














0












0








0







I tried to setup a reverse proxy with nginx, and after the changes I made, the page where I view our json data for our api (www.ourapihost.com/issues.json) is now timing out with the error



We're sorry but something went wrong. If you are the application owner check the logs for more information.



However, the logs are blank. I had to clear them because it was taking too long to cat the logfile, but when I try to refresh the page, it keeps timing out with the above error, and it's not adding anything to the log.



This is our current nginx configuration:



server {
listen 80; #443 ssl http2;



server_name <our server domain>;
root /home/deployer/ft_parks/current/public;
access_log /var/log/nginx/wilderness-patrol.net_access.log;
# error_log /var/log/nginx/wilderness-patrol.net_error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
keepalive_timeout 200;

error_page 500 502 503 504 /500.html;

try_files $uri @app;

# include /etc/nginx/snippets/letsencrypt-acme-challenge.conf;

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
location @app {
proxy_pass http://wp_server;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;

# location /issues {
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# proxy_pass http://<my ip>:3001/;
# }

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
location ~* .(jpg|jpeg|gif|png|css|js|ico|xml|svg)$ {
access_log off;
log_not_found off;
expires 30d;
}
}

location = /500.html {
root /home/deployer/ft_parks/current/public;
}
}


The location /issues block that is commented out is the section I added to try and add the reverse proxy. My webpack server is running on localhost:3001.



I have read several other related posts here on stackoverflow about this issue, and have tried all of the solutions they suggested, but none of them worked for me. I feel like I'm either missing something in my location /issues block, or that I'm just simply not writing it properly. I have also already tryed using the rack-cors gem, which I couldn't get working either.



Any advice? Thanks!










share|improve this question













I tried to setup a reverse proxy with nginx, and after the changes I made, the page where I view our json data for our api (www.ourapihost.com/issues.json) is now timing out with the error



We're sorry but something went wrong. If you are the application owner check the logs for more information.



However, the logs are blank. I had to clear them because it was taking too long to cat the logfile, but when I try to refresh the page, it keeps timing out with the above error, and it's not adding anything to the log.



This is our current nginx configuration:



server {
listen 80; #443 ssl http2;



server_name <our server domain>;
root /home/deployer/ft_parks/current/public;
access_log /var/log/nginx/wilderness-patrol.net_access.log;
# error_log /var/log/nginx/wilderness-patrol.net_error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
keepalive_timeout 200;

error_page 500 502 503 504 /500.html;

try_files $uri @app;

# include /etc/nginx/snippets/letsencrypt-acme-challenge.conf;

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
location @app {
proxy_pass http://wp_server;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;

# location /issues {
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# proxy_pass http://<my ip>:3001/;
# }

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
location ~* .(jpg|jpeg|gif|png|css|js|ico|xml|svg)$ {
access_log off;
log_not_found off;
expires 30d;
}
}

location = /500.html {
root /home/deployer/ft_parks/current/public;
}
}


The location /issues block that is commented out is the section I added to try and add the reverse proxy. My webpack server is running on localhost:3001.



I have read several other related posts here on stackoverflow about this issue, and have tried all of the solutions they suggested, but none of them worked for me. I feel like I'm either missing something in my location /issues block, or that I'm just simply not writing it properly. I have also already tryed using the rack-cors gem, which I couldn't get working either.



Any advice? Thanks!







ruby-on-rails nginx cors ruby-on-rails-5 reverse-proxy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 3:04









Elliot Tregoning

105112




105112












  • did you check your nginx access & error logs?
    – Lenin Raj Rajasekaran
    Nov 21 at 3:20










  • I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
    – Austio
    Nov 21 at 3:43










  • Nothing mentioned in the question indicates any CORS-related problem
    – sideshowbarker
    Nov 21 at 6:23










  • Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
    – Elliot Tregoning
    Nov 22 at 12:44


















  • did you check your nginx access & error logs?
    – Lenin Raj Rajasekaran
    Nov 21 at 3:20










  • I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
    – Austio
    Nov 21 at 3:43










  • Nothing mentioned in the question indicates any CORS-related problem
    – sideshowbarker
    Nov 21 at 6:23










  • Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
    – Elliot Tregoning
    Nov 22 at 12:44
















did you check your nginx access & error logs?
– Lenin Raj Rajasekaran
Nov 21 at 3:20




did you check your nginx access & error logs?
– Lenin Raj Rajasekaran
Nov 21 at 3:20












I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
– Austio
Nov 21 at 3:43




I would bet that your try_files is catching that issues request and rendering on rails server. have you tried moving the webpack server above that? Can you hit any of the assets or 500 page on nginx?
– Austio
Nov 21 at 3:43












Nothing mentioned in the question indicates any CORS-related problem
– sideshowbarker
Nov 21 at 6:23




Nothing mentioned in the question indicates any CORS-related problem
– sideshowbarker
Nov 21 at 6:23












Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
– Elliot Tregoning
Nov 22 at 12:44




Sorry for the delayed reply the server we use had some downtime today. sideshowbarker - yes it does. localhost isn't on the same domain. Austio - not sure I understand what you mean. I'm still kinda new to backend stuff. @emaillenin - yes, but as I'm new to backend stuff, I'm not really sure what I'm looking at/for. The access log has just 3 lines, and I'm not really sure what they mean. The only thing i understand from the error.log is that it says stuff about either the connection being refused, or the url prefix in the config file is invalid, but I don't really know what it should be.
– Elliot Tregoning
Nov 22 at 12:44

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404708%2fnginx-rails-how-do-i-make-an-api-call-from-a-webpack-server-on-localhost-to-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404708%2fnginx-rails-how-do-i-make-an-api-call-from-a-webpack-server-on-localhost-to-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python