Reputation: 4427
i have some question about using nginx. as you can see the title, i am trying to redirect http to https.
before read nginx code, i want to tell you that the main server made by node.js, and using https with custom port(i.e. 3000).
so what i gonna do is when user type "http://mywebsite.com" on the browser, redirect to "https://mywebsite.com".
this is my nginx code:
# http://mywebsite.com: redirect to https
server {
listen 80;
server_name mywebsite.com;
return 301 https://$server_name$request_uri;
}
# https
# redirect to 3000 port with https!
server {
listen 443 ssl;
server_name mywebsite.com
root ...
...
location / {
proxy_set_header X-Real-IP $remove_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://127.0.0.1:3000/;
proxy_redirect off;
}
...
this is the first time to using nginx so it is really hard to me. it will be very appreciate it that help me. thx!
Upvotes: 1
Views: 4382
Reputation: 126
if you need redirect all https to https, you must write co your global config:
server {
listen 80;
server_name mywebsite.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
Upvotes: 1