[英]nginx http to https redirect configuration not working
I have configured my nginx based on the documentation provided and articles available from web. 我已经根据提供的文档和可从Web获得的文章配置了nginx。 It's not completely working specifically http to https. 它不能完全正常工作到http到https。 I tried different changes but still not be able to execute successfully...Please have a look. 我尝试了其他更改,但仍然无法成功执行...请看看。
Few imp points : My . 几点建议:我的。 nodejs app is running on port 3000. Ghost blog running on 2368. nodejs应用程序在端口3000上运行。Ghost博客在2368上运行。
HTTP — redirect all traffic to HTTPS
server {
listen 80;
server_name domainname.com www.domainname.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name www.domainname.com;
error_page 497 https://www.domainname.com$request_uri;
ssl_certificate /etc/letsencrypt/live/domainname.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domainname.com/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# intermediate configuration. tweak to your needs.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers KEY_HERE;
ssl_prefer_server_ciphers on;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
## verify chain of trust of OCSP response using Root CA and Intermediate certs
# ssl_trusted_certificate /etc/ssl/certs/dhparam.pem;
resolver 8.8.8.8;
location / {
proxy_pass http://localhost:3000;
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;
}
location /blog {
proxy_pass http://localhost:2368;
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;
}
}
I recommend you to do as below: 我建议您执行以下操作:
location / {
return 301 https://$host$request_uri;
}
This issue is resolved. 此问题已解决。
Everything is correct with nginx configuration. 使用nginx配置,一切都正确。 Issue was with Google console platform. 问题出在Google控制台平台上。 There is a check box in GCP config with name Allow HTTP traffic, which was unchecked by default. GCP配置中有一个名为“允许HTTP通信”的复选框,默认情况下未选中。 I made the change and it started working. 我进行了更改,它开始起作用。 Thanks for the reply. 谢谢回复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.