nginx 配置 http 自动跳转到 https 问题

2019-09-11 13:03:08 +08:00
 chfight

现在 https 使用的是 8443 端口,想要实现访问 8443 端口的 http->https 自动跳转

例如访问 http://aaa.com:8443 -> https://aaa.com:8443

请问可以做到这样吗?

9711 次点击
所在节点    NGINX
34 条回复
gstqc
2019-09-11 13:08:54 +08:00
不能
ysc3839
2019-09-11 13:14:57 +08:00
可以,搜索 nginx http 497。
wnpllrzodiac
2019-09-11 13:16:38 +08:00
一个端口还能搞两个服务?
loading
2019-09-11 13:18:30 +08:00
我搜的关键字 https 非 80


现在 v 站越来越难发回复了,你自己搜吧
idclight
2019-09-11 13:24:22 +08:00
rewire 写法:
```
rewrite ^(.*)$ https://$host$1 permanent;
```
return 写法:
```
return 301 https://$server_name$request_uri;
```
idclight
2019-09-11 13:27:08 +08:00
没仔细审题(溜了
littlespider89
2019-09-11 13:41:08 +08:00
c2VydmVyIHsKICAgIGxpc3RlbiA4NDQzIHNzbDsKICAgIHNlcnZlcl9uYW1lIGFhYS5jb207CiAgICAKICAgICMgeW91ciBzZXJ2ZXIgY29uZmlnCgogICAgZXJyb3JfcGFnZSA0OTcgaHR0cHM6Ly9hYWEuY29tOjg0NDM7Cn0K
tulongtou
2019-09-11 13:45:46 +08:00
可以 error_page 497 https://$host:$server_port$request_uri;
kaikai5601
2019-09-11 14:03:51 +08:00
server 段加上
if ($server_port !~ 443){
rewrite ^(/.*)$ https://aaa.com:8443$1 permanent;
}
markgor
2019-09-11 14:07:11 +08:00
楼上的大哥,请问同域名同端口 nginx 是怎样区分服务?
markgor
2019-09-11 14:07:54 +08:00
题主的要求是
http://aaa.com:8443 -> https://aaa.com:8443
!(注意看端口号)
qsnow6
2019-09-11 14:09:43 +08:00
自己在代码上 listen 吧
chfight
2019-09-11 14:25:37 +08:00
mringg
2019-09-11 14:27:47 +08:00
个人感觉这个问题比较难
xfriday
2019-09-11 14:43:09 +08:00
楼上的一些同学可能没注意楼主的端口是同一个,一般的 http 跳 https 是因为端口 80 => 443 才能用,除非能同一个端口实现 2 种协议才行,否则 tls 握手都不行
MrUser
2019-09-11 14:50:26 +08:00
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
直接在 HTML 里加这个试试?
tulongtou
2019-09-11 14:57:01 +08:00
楼上一堆不看文档还乱讲话的,具体文档在这里: http://nginx.org/en/docs/http/ngx_http_ssl_module.html
salmon5
2019-09-11 14:57:18 +08:00
同端口同域名同主机,技术上应该不行,实际也没必要,直接 http 请求就 400 了,老老实实的用 https
nicoljiang
2019-09-11 15:13:08 +08:00
if ($scheme !~ 'https'){
rewrite ^(/.*)$ https://$host$1 permanent;
}

这样?
OldCarMan
2019-09-11 15:43:39 +08:00
8 楼的方式,我看行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/599989

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX