I have the following nginx config:
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /home/tom/local.tjrhodes.com.pem;
ssl_certificate_key /home/tom/local.tjrhodes.com-key.pem;
root /home/tom/Nextcloud/local.tjrhodes.com/webroot/;
error_log /home/tom/Nextcloud/local.tjrhodes.com/logs/error.log;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name local.tjrhodes.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /pat/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
I call the /pat/ path with fetch on the client but the port 3000 on the proxy_pass command is overwritten with 443 as I’m testing locally over https. What am I missing in the config?
`
I’ve tried the node server calling it directly with the correct port (127.0.0.1:3000) and it responds ok. I can’t make the request from the client when connecting over https though.
2
Answers
Ok, for completeness here is the config that works for me...
change your nginx config to this:
removed depricated
on ssl
and addedproxy_set_header X-Forwarded-Proto $scheme;
to forward the original protocol (HTTP or HTTPS) of the client request to the backend server