Ssl 从Nginx将HTTP重定向到HTTPS不起作用
类型:=>ssl正常 但是类型:www.example.com和example.com是httpno redirecthttps。(www重定向到非www) WordPress地址(URL)和站点地址(URL):https//example.com /etc/nginx/conf.d/example.com.confSsl 从Nginx将HTTP重定向到HTTPS不起作用,ssl,nginx,https,Ssl,Nginx,Https,类型:=>ssl正常 但是类型:www.example.com和example.com是httpno redirecthttps。(www重定向到非www) WordPress地址(URL)和站点地址(URL):https//example.com /etc/nginx/conf.d/example.com.conf server { listen 80; server_name example.com www.example.com; return 301 https://$server_n
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com www.example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/cert_chain.crt;
#ssl_CACertificate_File /etc/nginx/ssl/example.com.ca-bundle;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
access_log off;
# access_log /home/example.com/logs/access_log;
error_log off;
# error_log /home/example.com/logs/error.log;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
root /home/example.com/public_html;
include /etc/nginx/conf/ddos2.conf;
index index.php index.html index.htm;
server_name example.com;
如何修复它?
对不起,我的英语不好,谢谢。您的配置不清楚,您最后有一行重复的
server\u name example.com
行
尝试使用以下方法:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
您的配置不清楚,最后有一个重复的
server\u name example.com
行
尝试使用以下方法:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
此代码将帮助您重定向到https: 如果输入,则它将重定向到
, 如果有人进入http:example.com,它将重定向到
服务器名www.example.com
DocumentRoot/usr/local/apache2/htdocs
重定向永久/https://www.example.com/
服务器名www.example.com
DocumentRoot/usr/local/apache2/htdocs
斯伦金安
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^(www\)?示例\.com$
重写规则(.*)https://www.example.com/$1[R=301,L]
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^example\.com$
重写规则(.*)https://www.example.com/$1[R=301,L]
此代码将帮助您重定向到https:
如果输入,则它将重定向到, 如果有人进入http:example.com,它将重定向到
服务器名www.example.com
DocumentRoot/usr/local/apache2/htdocs
重定向永久/https://www.example.com/
服务器名www.example.com
DocumentRoot/usr/local/apache2/htdocs
斯伦金安
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^(www\)?示例\.com$
重写规则(.*)https://www.example.com/$1[R=301,L]
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^example\.com$
重写规则(.*)https://www.example.com/$1[R=301,L]
这可能是由于服务器名称不明确造成的。尝试使用以下方法:
server {
server_name example.com www.example.com;
listen 80;
listen 443 ssl; # Listen for SSL at port 443 as well
# ... other config - certificates and such
# If a user tries to come through http, redirect them through https
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
}
您可以通过运行
sudo nginx-t
来检查您的nginx配置。这可能是由于服务器名称不明确造成的。尝试使用以下方法:
server {
server_name example.com www.example.com;
listen 80;
listen 443 ssl; # Listen for SSL at port 443 as well
# ... other config - certificates and such
# If a user tries to come through http, redirect them through https
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
}
您可以通过运行
sudonginx-t
来检查nginx配置,我遇到了类似的问题。这是由linux防火墙引起的(不允许使用端口80)。我也有类似的问题。这是由linux防火墙引起的(不允许使用端口80)。您在服务器配置中启用了https支持吗?是的,我启用了。您在服务器配置中启用了https支持吗?是的,我启用了。我尝试了,并删除了重复的代码server\u name example.com
。重新启动nginx,但我的问题仍然是#服务nginx重新启动nginx:[警告]冲突服务器名称“example.com”于0.0.0:80,忽略nginx:[警告]冲突服务器名称“www.example.com”于0.0.0:80,忽略nginx:[警告]冲突服务器名称“example.com”,忽略停止nginx:[确定]启动nginx:nginx:[警告]冲突的服务器名称“example.com”位于0.0.0:80,忽略了nginx:[警告]冲突的服务器名称“www.example.com”位于0.0.0:80,忽略了nginx:[警告]冲突的服务器名称“example.com”位于0.0.0:80,忽略了
检查您只有一个服务器{listen 80…
您可以先尝试我放在这里的块,然后启用其他块,使用nginx-t
在/etc/nginx/conf.d/example.com.conf中测试configCheck only?nginx-t nginx:etc/nginx/nginx.conf语法正常nginx:configuration file/etc/nginx/nginx.conf测试成功
我尝试了一下,并删除了重复的代码server\u name example.com
。重新启动nginx,但我的问题仍然是#服务nginx重新启动nginx:[warn]冲突的服务器名称“example.com”(0.0.0:80),忽略了nginx:[warn]冲突的服务器名称“www.example.com”(0.0.0:80),忽略了nginx:[warn]冲突的服务器名称0.0.0.0:80上的“example.com”,忽略停止nginx:[确定]启动nginx:nginx:[警告]冲突的服务器名称“example.com”,0.0.0:80上的nginx:[警告]冲突的服务器名称“www.example.com”,忽略nginx:[警告]冲突的服务器名称“example.com”“在0.0.0.0:80,忽略
检查您只有一个服务器{listen 80…
您可以先尝试我放在这里的块,然后启用其他块,使用nginx-t
在/etc/nginx/conf.d/example.com.conf中测试configCheck only?nginx-t nginx:etc/nginx/nginx.conf语法正常nginx:configuration file/etc/nginx/nginx.conf测试成功代码>