http强制跳到 https带www nginx配置问题,大佬看下哪的问题
本帖最后由 akige 于 2018-5-1 21:20 编辑配置如下 ssl的就不放出来了。没问题。
这样写看着没错啊?,就是跳不过去。
server {
listen 80;
server_nameaaa.com;
return 301 https://www.aaa.com$request_uri;
}
server {
listen 80;
server_namewww.aaa.com;
return 301 https://www.aaa.com$request_uri;
}
server {
listen 443;
server_nameaaa.com;
return 301 https://www.aaa.com$request_uri;
}
我的需求就是
1. xxx.com/a.html 跳到https://www.xxx.com/a.html
2. www.xxx.com/a.html 跳到https://www.xxx.com/a.html
3. https://xxx.com/a.html 跳到https://www.xxx.com/a.html
完事。 rewrite ^/(.*)$ https://www.xxx.com/$1 permanent;
https://liyuans.com/archives/http-automatic-jump-https.html
看看这个 loti 发表于 2018-5-1 21:20
https://liyuans.com/archives/http-automatic-jump-https.html
看看这个
http跳转到https我会。但是有这样一个问题。 aaa.com会跳转到 https://aaa.com我需要统一https://www.aaa.com类似百度那样 本帖最后由 march1993 于 2018-5-1 21:34 编辑
server_name 可以填多个,return 的时候会返回第一个
两个 if 没法合并,nginx 不支持
listen 80 default_server default_server;
listen 443 ssl default_server default_server;
server_name www.xxx.com xxx.com yyy.com;
if ($http_host != $server_name) {
return 301 https://$server_name$request_uri;
}
if ($scheme = http) {
return 301 https://$server_name$request_uri;
} server_name baidu.com www.baidu.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != baidu.com) {return 301 $scheme://baidu.com$request_uri;}
www到no www
server_name www.baidu.com baidu.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != www.baidu.com) {return 301 $scheme://www.baidu.com$request_uri;
no www到www
分开写干嘛。。。 陈道临 发表于 2018-5-1 21:42
server_name baidu.com www.baidu.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; ...
你这个如果是 http://baidu.com 会 301 两次的吧? 第一次到 https://baidu.com 第二次到 https://www.baidu.com march1993 发表于 2018-5-1 21:29
server_name 可以填多个,return 的时候会返回第一个
两个 if 没法合并,nginx 不支持
...
server {
listen 80 ;
listen 443 ssl http2;
index index.html index.htm index.php default.html default.htm default.php;
server_name www.mysite.com mysite.com;
if ($http_host != $server_name) {
return 301 https://$server_name$request_uri;
}
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
}
server
{
listen 80;
#listen [::]:80;
server_name www.mysite.com mysite.com;
# index index.html index.htm index.php default.html default.htm default.php;
root/home/wwwroot/www.mysite.com;
include rewrite/laravel.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log/home/wwwlogs/www.mysite.com.log;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.mysite.com ;
index index.html index.htm index.php default.html default.htm default.php;
root/home/wwwroot/www.mysite.com;
ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/www.mysite.com/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/www.mysite.com/www.mysite.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/laravel.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log/home/wwwlogs/www.mysite.com.log;
}
报错:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete. march1993 发表于 2018-5-1 21:44
你这个如果是 会 301 两次的吧? 第一次到第二次到
分开用return 301 https://www.baidu.com$request_uri;也行啊 陈道临 发表于 2018-5-1 21:42
server_name baidu.com www.baidu.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; ...
这一段写在listen 80443 端口都要加吗?