lnmpa 重定向问题
本帖最后由 caiheqing 于 2021-5-17 17:23 编辑今天在网站配置文件里面加了一个301跳转,结果页面就显示重定向太多,如果去掉可以打开,但不能跳转到https页面,代码如下
我把完整的代码补上一下
server
{
listen 80;
#listen [::]:80;
server_name www.baidu.com baidu.com;
if ($host != 'www.baidu.com' )
{
rewrite ^/(.*)$ https://www.baidu.com/$1 permanent;
}
if( $http_user_agent ~* "(iPhone|iPad|iPod|iOS|Android|Mobile|nokia|samsung|htc|blackberry)")
{
rewrite ^/tag/(.*)$ https://m.baidu.com/tag/$1 permanent;
}
index index.html index.php;
root/home/wwwroot/www.baidu.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.baidu.com/$1 permanent;
}
include proxy-pass-php.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 off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.baidu.com baidu.com;
index index.html index.php;
root/home/wwwroot/www.baidu.com;
ssl_certificate /usr/local/nginx/conf/ssl/www.baidu.com/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/www.baidu.com/www.baidu.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256: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;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include proxy-pass-php.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 off;
}
按贴出的配置文件没啥问题
你网站目录下是否有.htaccess 看一下是否有设置301 licess 发表于 2021-5-18 13:42
按贴出的配置文件没啥问题
你网站目录下是否有.htaccess 看一下是否有设置301 ...
谢谢军哥的回复,我重新修改了一下代码,现在有一个问题是http不能跳转到https,目录也一样,我把代码放上,麻烦军哥看看,网址是:http://www.snsnz.com
比如目录http://www.snsnz.com/yinle 不能跳转到https://www.snsnz.com/yinle
http://www.snsnz.com 不能跳转到https://www.snsnz.com
server
{
listen 80;
#listen [::]:80;
server_name snsnz.com;
return 301 https://www.snsnz.com$request_uri;
if ($host = 'snsnz.com' )
{
return 301 https://www.snsnz.com$request_uri;
}
if( $http_user_agent ~* "(iPhone|iPad|iPod|iOS|Android|Mobile|nokia|samsung|htc|blackberry)")
{
rewrite ^/tag/(.*)$ https://m.snsnz.com/tag/$1 permanent;
}
index index.html index.php;
root/home/wwwroot/www.snsnz.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.snsnz.com/$1 permanent;
}
include proxy-pass-php.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 off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.snsnz.com;
index index.html index.php;
root/home/wwwroot/www.snsnz.com;
ssl_certificate /usr/local/nginx/conf/ssl/www.snsnz.com/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/www.snsnz.com/www.snsnz.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256: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;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include proxy-pass-php.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 off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name snsnz.com;
return 301 https://www.snsnz.com$request_uri;
index index.html index.php;
root/home/wwwroot/www.snsnz.com;
ssl_certificate /usr/local/nginx/conf/ssl/www.snsnz.com/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/www.snsnz.com/www.snsnz.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256: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;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include proxy-pass-php.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 off;
}
现在又出现一个问题,文件夹里面的CSS和JS都无法访问得到,都出现404,但文件是存在的,是怎么回事? caiheqing 发表于 2021-5-18 14:36
谢谢军哥的回复,我重新修改了一下代码,现在有一个问题是http不能跳转到https,目录也一样,我把代码放 ...
你虚拟主机里都没添加带www的域名,肯定也就无法跳转了
你最前面就加了个301跳转,下面你写那么多if也是一个都不会匹配了,第一个return就已经结束不再进行下面的各种if了 licess 发表于 2021-5-20 08:16
你虚拟主机里都没添加带www的域名,肯定也就无法跳转了
你最前面就加了个301跳转,下面你写那么多if也是 ...
谢谢军哥的回复,本来我是这样考虑,如果80端口我多写一个server,但测试配置文件会提示警告,现在server_name我加带www的,如果写一个return则显示此页面不能正确地重定向问题,这个真不知道怎么修改了,我是搬了服务器才显示这个问题,之前老服务器同样的配置没问题的,军哥,这个怎么修改 caiheqing 发表于 2021-5-20 09:28
谢谢军哥的回复,本来我是这样考虑,如果80端口我多写一个server,但测试配置文件会提示警告,现在server ...
上面贴出的配置文件除上面指出的外没有其他问题
有警告,说明其他配置文件是由问题的
如果使用了cdn,检查cdn上的设置
页:
[1]