I'm trying to setup nginx so that it pull the app running on port 3000.
When I visit mydomain.com:3000, the app works. I want it to run without the port.
I have nginx setup and it's working properly. I have an SSL cert setup and it's working properly (I'm able to see the nginx start page with SSL) I have the www redirect working properly.
The part I want to do now is take what is running on port 3000 and have it run on port 80.
Here is my config file:
upstream myapp {
server 127.0.0.1:3000;
}
server {
#listen 80 is default
server_name www.mydomain.com;
return 301 $scheme://mydomain.com$request_uri;
}
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
ssl on;
ssl_certificate /root/certs/bundle.crt;
ssl_certificate_key /root/certs/mydomain.key;
server_name mydomain.com;
if ($ssl_protocol = "") {
rewrite ^ https://$server_name$request_uri? permanent;
}
location / {
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_redirect off;
try_files @node $uri.html;
}
location @node {
proxy_pass https://myapp;
}
}
When I visit the page with this setup, I get a 500 internal server error. What am I doing wrong?
By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port. However, the TLS configuration, which is not supported in Nginx by default, listens to port 443 for secure connections.
I figured it out, since I was using SSL, I needed to make sure it was https. Here is my final config:
upstream app_nodejs {
server 127.0.0.1:3000;
}
server {
#listen 80 is default
server_name www.mydomain.com;
return 301 $scheme://mydomain.com$request_uri;
}
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
ssl on;
ssl_certificate /root/certs/bundle.crt;
ssl_certificate_key /root/certs/mydomain.key;
server_name mydomain.com;
if ($ssl_protocol = "") {
rewrite ^ https://$server_name$request_uri? permanent;
}
location / {
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_pass https://app_nodejs;
proxy_redirect off;
}
}
server {
listen 80;
server_name p3000;
location / {
proxy_pass http://0.0.0.0:3000;
include /etc/nginx/proxy_params;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With