当前位置: 首页 > 后端技术 > Node.js

nginx配置http重定向(redirect)https

时间:2023-04-03 14:48:30 Node.js

之前的配置server{listen80listen443sslhttp2;服务器名称www.ohmygod.com;位置/{proxy_passhttp://localhost:4444;#portnumberproxy_set_header主机$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}}搜索之后,只需要简单的加上一句rewrite^(.*)$https://$host$1permanent;可以,所以直接加到server_name;提示redirects太多了,再清楚cookie也不管用。打开网站f12查看,发现浏览器不断的请求,301...同事指出了一个很愚蠢的错误后,因为重定向配置在80和443端口,导致重复重定向,而且是解决问题很简单。把80端口拿出来重定向就行了,然后修改配置为server{listen80;服务器名称www.ohmygod.com;#RedirectHTTP301toHTTPSrewrite^(.*)$https://$host$1permanent;}server{listen443sslhttp2;服务器名称www.ohmygod.com;位置/{proxy_passhttp://localhost:4444;#portnumberproxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;临xy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}}