问:技术您好!
现在我有个站刚转移到西数,并部署了SSL,域名是 https://www.bbqiming.com/
因为原来这个www(pc站)有一个手机站https://m.bbqiming.com/,(www和m在不同的主机上面)也部署了SSL。
现在需求是nginx的规则如何写,才能实现:
用户访问手机端https://m.bbqiming.com/ 时301跳转到PC端的https://www.bbqiming.com/ ?
访问手机端https://m.bbqiming.com/news/ 时301跳转到 https://www.bbqiming.com/news/ ?
也就是如何做https跳转到对应的https的URL上面
再次强调需求:是做https 301跳转 到https ,并不是http跳转到https。
原http跳转到https的nginx规则如下:
server {
listen 443 ssl;
server_name m.bbqiming.com;
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
请技术员根据上述需求帮忙修改一下规则实现,谢谢!
答:您好,1、查看到您当前反馈的规则已经可以将对应的https://m.bbqiming.com/ 跳转到https://www.bbqiming.com/ ,请核实。非常感谢您长期对我司的支持!
问:您好!你误解我上述需求了吧?
我目测你只测试了 (非https) http://m.bbqiming.com/ 这种情况吧? 这个我知道,上述的
server {
listen 443 ssl;
server_name m.bbqiming.com;
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
这个规则是能实现了M域名的 http 301跳转到PC域名的https 。
但我上述的实际需求是:上述规则怎么修改,才能实现 M域名的https 跳转到PC域名的HTTPS ?
也即最终的效果是要实现:
用户访问https://m.bbqiming.com/(注 M域名是HTTPS URL) 301跳转到https://www.bbqiming.com/
用户访问 https://m.bbqiming.com/nandaquan/201711/.html (注 M域名是HTTPS URL)301跳转到 https://www.bbqiming.com/nandaquan/201711/.html
答:您好,您试试在之前的服务器站点配置文件
server_name m.bbqiming.com;
下添加
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
试试看
https://m.bbqiming.com/ 是否可以跳转,非常感谢您长期对我司的支持!
问:按您上述方法试了,还是不行呢,我将原服务器的整个配置文件贴出来你看看:
server {
listen 443 ssl;
/www/web/bbqm170731/public_html/wap;
server_name m.bbqiming.com m.bbqiming.com;
index index.html;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 405 /errpage/405.html;
error_page 500 /errpage/500.html;
error_page 503 /errpage/503.html;
ssl on;
ssl_certificate cert/m.bbqiming.com.pem;
ssl_certificate_key cert/m.bbqiming.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location ~\\.(php|php5|htm|rar|tar|gz|zip|asp|aspx)$ {
deny all;
return 444;
}
access_log /www/web_logs/m.bbqiming.com_access.log wwwlogs;
error_log /www/web_logs/m.bbqiming.com_error.log;
}
server {
listen *:80;
server_name m.bbqiming.com;
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
server {
listen 443 ssl;
server_name m.bbqiming.com;
if ($host ~* m.bbqiming.com) {
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
rewrite ^/(.*)$ https://www.bbqiming.com/$1 permanent;
}
下面是我按上述配置并重启服务器后,测试的附图:
答:您好,
查看您域名m.bbqiming.com 解析到127.0.0.1 这个IP,该IP不是我司的,需要在这个IP上设置正确的301才会生效,建议您联系主机提供商协助您设置一下。
,非常感谢您长期对我司的支持.由此给您带来的不便之处,敬请原谅!谢谢!