[英]Nginx redirect https://www to https://
Thanks Richard for the Answer! 感谢理查德的答案!
I have just set up my SSL certificates from Comodo on a Digitalocean Ubuntu rails server with Nginx. 我刚刚使用Nginx在Digitalocean Ubuntu Rails服务器上从Comodo设置了SSL证书。
At the moment http:// www.mydomain and http:// mydomain redirect to https:// mydomain 目前,http:// www.mydomain和http:// mydomain重定向到https:// mydomain
I also want https:// www.mydomain to redirect to https:// mydomain 我还希望https:// www.mydomain重定向到https:// mydomain
I am very new to this and this is the current setup, I have 2 /etc/nginx/sites-enabled/ files( a .com and a .com.ssl file): 我对此很陌生,这是当前设置,我有2个/ etc / nginx / sites-enabled /文件(.com和.com.ssl文件):
.com file .com文件
server {
listen 80;
server_name dspencer-webdesign.com;
return 301 https://dspencer-webdesign.com$request_uri;
}
server {
listen 80;
server_name dspencer-webdesign.com;
passenger_enabled on;
rails_env production;
root /home/abfahren/david/current/public;
error_page 500 502 503 504 /50x.html;
location = /50.x.html {
root html;
}
}
.com.ssl file .com.ssl文件
server {
server_name www.dspencer-webdesign.com;
return 301 $scheme://dspencer-webdesign.com$request_uri;
}
server {
listen 443 ssl;
server_name dspencer-webdesign.com;
ssl_certificate /etc/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/dspencer-webdesign.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
passenger_enabled on;
rails_env production;
root /home/abfahren/david/current/public;
error_page 500 502 503 504 /50x.html;
location = /50.x.html {
root html;
}
}
I am not sure how to get the functioning https:// www to redirect to https://dspencer-webdesign.com 我不确定如何使运行中的https:// www重定向到https://dspencer-webdesign.com
Any help would be greatly appreciated Cheers 任何帮助将不胜感激
Your configuration is a little confusing. 您的配置有些混乱。 You have three non-SSL
server
containers, two of which have the same server_name
. 您有三个非SSL
server
容器,其中两个具有相同的server_name
。 #1 redirects to SSL, #2 is never used, and #3 redirects to #1. #1重定向到SSL,从不使用#2,#3重定向到#1。
Your 4th server
container is your one and only SSL server
container, which makes it your default server for any connections to port 443. 第四个
server
容器是您唯一的SSL server
容器,这使其成为与端口443进行任何连接的默认服务器。
I haven't tested this, but if you place this near the top of the SSL server block it should redirect https://www.dw.c
to https://dw.c
: 我尚未测试过,但是如果将其放置在SSL服务器块的顶部附近,则应将
https://www.dw.c
重定向到https://dw.c
:
server {
listen 443 ssl;
server_name dspencer-webdesign.com;
if ($server_name ~* \.dspencer-webdesign.com$) {
return 301 $scheme://dspencer-webdesign.com$request_uri;
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.