如何在NGINX上将HTTPS重定向到HTTP?
是否可以通过在域的vhost文件中添加规则将HTTPS请求重定向到HTTP?
Is there a way to redirect HTTPS requests to HTTP by adding a rule in the domain's vhost file?
为什么这样有用?乍一看,我不确定是否可以做到.但这提出了一个有趣的问题.
Why is something like that useful? At first look I wasn't sure if it could be done. But it presented an interesting question.
您可以尝试将重定向语句放入配置文件中,然后重新启动服务器.可能发生两种可能性:
You might try putting a redirect statement in your config file and restarting your server. Two possibilities might happen:
- 服务器将发出重定向-您似乎想要的.
- 服务器将首先进行https交换,然后发出重定向,在这种情况下,有什么意义?
如果我想出更具体的内容,还会添加更多内容.
Will add more if I come up with something more concrete.
更新:(几个小时后) 你可以试试看.您需要将其放入您的 nginx.conf 文件-
UPDATE: (couple of hours later) You could try this. You need to put this in your nginx.conf file -
server {
listen 443;
server_name _ *;
rewrite ^(.*) http://$host$1 permanent;
}
发送永久重定向到客户端.我假设您使用的是https的端口443(默认).
Sends a permanent redirect to the client. I am assuming you are using port 443 (default) for https.
server {
listen 80;
server_name _ *;
...
}
添加此内容,以便您在端口80上的常规http请求不受干扰.
Add this so that your normal http requests on port 80 are undisturbed.
更新: 2016年12月18日
-在版本> 0.6.25的Nginx中,应使用server_name _
代替server_name _ *
(感谢@Luca Steeb)
UPDATE: 18th Dec 2016
- server_name _
should be used instead of server_name _ *
in nginx versions > 0.6.25 (thanks to @Luca Steeb)