Hello, I am trying to redirect my http traffic to https and also proxy_pass to port 5000… i cannot get it to work? what am i doing wrong…?
server {
listen 80;
listen [::]:80;
root /var/www/this/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://localhost:5000;
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;
}
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!
Everything looks perfectly fine from my point of view. Anyway, here is how I usually do such configs. Please give it a try and let me know how it goes :
#This server block will redirect http:// to https://www.mysite.com
server {
listen 80;
listen [::]:80;
server_name mysite.com www.mysite.com;
return 301 https://www.mysite.com$request_uri;
}
#This server block will redirect https://mysite.com to https://www.mysite.com (expecting that you have a certificate for mysite.com as well as www.mysite.com
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/ssl-www.mysite.com.conf;
include snippets/ssl-params.conf;
server_name mysite.com;
return 301 https://www.$server_name$request_uri;
}
#This is the server block actually delivering content to the visitor
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-www.mysite.com.conf;
include snippets/ssl-params.conf;
server_name www.mysite.com;
client_max_body_size 100M;
location ~ ^/\.well-known {
root /var/www/ghost;
allow all;
}
location / {
proxy_pass http://127.0.0.1:5000;
proxy_buffering off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Referer "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
}
Remember to change mysite.com with your actual domain! Once you do make the changes, please don’t forget to actually restart Nginx.
Looking forward to your reply
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.