现在 https 使用的是 8443 端口,想要实现访问 8443 端口的 http->https 自动跳转
例如访问 http://aaa.com:8443 -> https://aaa美国服务器.com:8443
请问可以做到这样吗?
不能
可以,搜索 nginx http 497。
一个端口还能搞两个服务?
我搜的关键字 https 非 80
现在 v 站越来越难发回复了,你自己搜吧
rewire 写法:
```
rewrite ^(.*)$ https://$host$1 permanent;
```
return 写法:
```
return 301 https://$server_name$request_uri;
```
没仔细审题(溜了
c2VydmVyIHsKICAgIGxpc3RlbiA4NDQzIHNzbDsKICAgIHNlcnZlcl9uYW1lIGFhYS5jb207CiAgICAKICAgICMgeW91ciBzZXJ2ZXIgY29uZmlnCgogICAgZXJyb3JfcGFnZSA0OTcgaHR0cHM6Ly9hYWEuY29tOjg0NDM7Cn0K
可以 error_page 497 https://$host:$server_port$request_uri;
server 段加上
if ($server_port !~ 443){
rewrite ^(/.*)$ https://aaa.com:8443$1 permanent;
}
楼上的大哥,请问同域名同端口 nginx 是怎样区分服务?
题主的要求是
http://aaa.com:8443 -> https://aaa.com:8443
!(注意看端口号)
自己在代码上 listen 吧
多谢各位
个人感觉这个问题比较难
楼上的一些同学可能没注意楼主的端口是同一个,一般的 http 跳 https 是因为端口 80 => 443 才能用,除非能同一个端口实现 2 种协议才行,否则 tls 握手都不行
直接在 HTML 里加这个试试?
楼上一堆不看文档还乱讲话的,具体文档在这里: http://nginx.org/en/docs/http/ngx_http_ssl_module.html
同端口同域名同主机,技术上应该不行,实际也没必要,直接 http 请求就 400 了,老老实实的用 https
if ($scheme !~ 'https'){
rewrite ^(/.*)$ https://$host$1 permanent;
}
这样?
8 楼的方式,我看行。
Nginx 可以一个端口同时提供 HTTP 和 HTTPS 服务!!??
server {
listen 80;
listen 443 ssl;
server_name a.com;
rewrite ^ $scheme://www.a/$request_uri permanent;
}
有点蒙,一个端口上同时监听 http 和 https?
https 不是和 443 绑定的吗,怎么还能强制 https 与特定非 443 端口绑定?
没有什么需求是加一个中间层解决不了的。
http 和 https 的协议是不一样的, http 上来就是发 get/post 请求,https 的话 应该是 ssl 的握手封包。 做个中间层,判断下上来的前几个字符,是 http 就做个 https 跳转,其他的全部放行。
楼主的问题是:针对 HTTPS 协议端口,客户端使用了错误的协议时该如何响应。这时候就需要把客户端引导到 HTTPS 协议上。
解决办法详见 8 楼和 17 楼。
当然可以,协议是协议,端口是端口,80、443 只是 http 和 https 的默认端口而已
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
无解
同一个端口搞两个?写 lua 呗,反正写规则肯定是不行。。。
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;preload" always;
if ($scheme = "http") {
rewrite ^/(.*)$ https://$server_name:$server_port/$1 permanent;
}
同样遇到这个问题,443 和 80 不能用,ssl 监听了其它端口,后端 Java 域名+端口没问题。前端服务域名+端口访问报 400 Bad request。页面进不去
我是 nginx 分别反向代理到前后端