server {
listen 80;
server_name greatwallprojects.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /pingtest/ {
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
The second application pingtest is not displayed. My application folders lie in home/user/
You can check the problem by visiting http://greatwallprojects.com/pingtest/ a blank page is displayed.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
First, it’s important to ensure that both your Node.js applications are running correctly on their respective ports (8080 for the main application, and 8081 for the /pingtest/ application).
Once you have confirmed that, let’s check your NGINX configuration. From what you’ve shared, it seems like the configuration is generally correct. However, when using the location directive to serve a Node.js app from a subdirectory (in your case /pingtest/), there can be issues related to the way paths are handled.
By default, when you use
proxy_pass
with the URL path specified (http://127.0.0.1:8081), Nginx will pass the exact same request URI to the upstream server. So, when you’re visitinghttp://greatwallprojects.com/pingtest/
, Nginx is trying to servehttp://127.0.0.1:8081/pingtest/
, which might not be correctly handled by your Node.js app.To solve this, you can use a URI in the
proxy_pass
directive. This will cause Nginx to replace the part of the request URI that matches the location path with the path specified in theproxy_pass
directive.Here’s how you can modify your configuration:
This configuration uses the
rewrite
directive to rewrite the request URI, stripping out the /pingtest/ part, before passing the request to your Node.js application.After making these changes, don’t forget to test your configuration and reload Nginx:
Please note that your Node.js application should be set up to correctly handle requests based on this configuration. If the application is expecting requests to be at /pingtest/, you will need to adjust its routing accordingly.