Last active
January 12, 2023 14:47
-
-
Save apollolm/23cdf72bd7db523b4e1c to your computer and use it in GitHub Desktop.
Nginx Configuration with multiple port apps on same domain, with SSL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the IP(s) on which your node server is running. I chose port 3000. | |
upstream app_geoforce { | |
server 127.0.0.1:3000; | |
} | |
upstream app_pcodes{ | |
server 127.0.0.1:3001; | |
} | |
#Point http requests to https | |
server { | |
listen 0.0.0.0:80; | |
server_name sub.domain.org; | |
server_tokens off; | |
return 301 https://$host$request_uri; | |
} | |
# the secure nginx server instance | |
server { | |
listen 443 ssl; | |
ssl_certificate /etc/nginx/ssl/public.crt; | |
ssl_certificate_key /etc/nginx/ssl/private.rsa; | |
server_name sub.domain.org; | |
access_log /var/log/nginx/myapp.log; | |
error_log /var/log/nginx/myapp_error.log; | |
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options | |
location /favicon.ico { alias /home/ubuntu/img/favicon_rc.ico; } | |
location / { | |
# auth_basic "Restricted"; | |
# auth_basic_user_file /home/ubuntu/app/.htpasswd; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_set_header X-Ssl on; | |
proxy_pass https://app_geoforce; | |
proxy_redirect off; | |
} | |
location /pcodes/ { | |
rewrite /pcodes/(.*)$ /$1 break; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_set_header X-Ssl on; | |
proxy_pass https://app_pcodes; | |
proxy_redirect off; | |
} | |
} |
this case ? how
mysite.com:3300
Help me guys
Had trouble getting location /first_game/
to work until i wrote the reqwrite part thanks!
rewrite /intra/(.*)$ /$1 break;
This is the line i was missing. ty you sage.
thanks! the rewrite line saved my day!
The rewrite line is the key!
This has helped me solving a BIG
issue i was facing for CORS
issue for Odoo backend server. Thanks a lot! 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created a config file that looks like this:
Everything seems to be working fine except for when I try to access the back-end api in the location /api/ block to redirect the traffic to port 3000 in the localhost. In that case, I get a 404 error and I can see in Firefox's debugging tools that NGINX returns its 404 page.
When I try to access that back-end API the URL looks like this: https://edafos.eng.yorku.ca/api/example
Does anyone here know what I could do to fix the problem?
UPDATE: my project is a MERN application where the front-end is served on port 80 and the back-end is redirected to localhost:3000. If my theory is correct, the problem in my config file is the root. Therefore, when I type in https://edafos.eng.yorku.ca/api/example it will try to redirect me to /var/www/Interface-2.0/Client/dist/api/example which obviously does not exist and returns me error 404. Can anyone confirm my thinking is right and, if it is, propose a fix?