VPS侦探论坛

 找回密码
 注册
查看: 4050|回复: 7

lnmpa 重定向问题

[复制链接]
发表于 2021-5-17 17:22:40 | 显示全部楼层 |阅读模式

本帖最后由 caiheqing 于 2021-5-17 17:23 编辑

今天在网站配置文件里面加了一个301跳转,结果页面就显示重定向太多,如果去掉可以打开,但不能跳转到https页面,代码如下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-5-17 17:45:00 | 显示全部楼层


我把完整的代码补上一下
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;
    }


Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2021-5-18 13:42:33 | 显示全部楼层

按贴出的配置文件没啥问题
你网站目录下是否有.htaccess 看一下是否有设置301
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-5-18 14:36:41 | 显示全部楼层



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



  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name snsnz.com;
  6.                 return 301 https://www.snsnz.com$request_uri;
  7.                 if ($host = 'snsnz.com' )
  8.         {
  9.           return 301 https://www.snsnz.com$request_uri;
  10.         }
  11.         if  ( $http_user_agent ~* "(iPhone|iPad|iPod|iOS|Android|Mobile|nokia|samsung|htc|blackberry)")
  12.         {
  13.            rewrite ^/tag/(.*)$ https://m.snsnz.com/tag/$1 permanent;
  14.         }
  15.         index index.html index.php;
  16.         root  /home/wwwroot/www.snsnz.com;

  17.         #error_page   404   /404.html;

  18.         # Deny access to PHP files in specific directory
  19.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  20.                
  21.         location ~* ^/m/
  22.         {
  23.            rewrite ^/m/(.*)$ https://m.snsnz.com/$1 permanent;
  24.         }       

  25.         include proxy-pass-php.conf;

  26.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  27.         {
  28.             expires      30d;
  29.         }

  30.         location ~ .*\.(js|css)?$
  31.         {
  32.             expires      12h;
  33.         }

  34.         location ~ /.well-known {
  35.             allow all;
  36.         }
  37.    
  38.         location ~ /\.
  39.         {
  40.             deny all;
  41.         }

  42.         access_log off;
  43.     }

  44. server
  45.     {
  46.         listen 443 ssl http2;
  47.         #listen [::]:443 ssl http2;
  48.         server_name www.snsnz.com;
  49.         index index.html index.php;
  50.         root  /home/wwwroot/www.snsnz.com;

  51.         ssl_certificate /usr/local/nginx/conf/ssl/www.snsnz.com/fullchain.cer;
  52.         ssl_certificate_key /usr/local/nginx/conf/ssl/www.snsnz.com/www.snsnz.com.key;
  53.         ssl_session_timeout 5m;
  54.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  55.         ssl_prefer_server_ciphers on;
  56.         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";
  57.         ssl_session_cache builtin:1000 shared:SSL:10m;
  58.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  59.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  60.         #error_page   404   /404.html;

  61.         # Deny access to PHP files in specific directory
  62.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  63.         include proxy-pass-php.conf;

  64.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  65.         {
  66.             expires      30d;
  67.         }

  68.         location ~ .*\.(js|css)?$
  69.         {
  70.             expires      12h;
  71.         }

  72.         location ~ /.well-known {
  73.             allow all;
  74.         }

  75.         location ~ /\.
  76.         {
  77.             deny all;
  78.         }

  79.         access_log off;
  80.     }
  81. server
  82.     {
  83.         listen 443 ssl http2;
  84.         #listen [::]:443 ssl http2;
  85.         server_name snsnz.com;
  86.                 return 301 https://www.snsnz.com$request_uri;
  87.         index index.html index.php;
  88.         root  /home/wwwroot/www.snsnz.com;

  89.         ssl_certificate /usr/local/nginx/conf/ssl/www.snsnz.com/fullchain.cer;
  90.         ssl_certificate_key /usr/local/nginx/conf/ssl/www.snsnz.com/www.snsnz.com.key;
  91.         ssl_session_timeout 5m;
  92.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  93.         ssl_prefer_server_ciphers on;
  94.         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";
  95.         ssl_session_cache builtin:1000 shared:SSL:10m;
  96.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  97.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  98.         #error_page   404   /404.html;

  99.         # Deny access to PHP files in specific directory
  100.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  101.         include proxy-pass-php.conf;

  102.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  103.         {
  104.             expires      30d;
  105.         }

  106.         location ~ .*\.(js|css)?$
  107.         {
  108.             expires      12h;
  109.         }

  110.         location ~ /.well-known {
  111.             allow all;
  112.         }

  113.         location ~ /\.
  114.         {
  115.             deny all;
  116.         }

  117.         access_log off;
  118.     }       
复制代码




Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2021-5-19 11:48:37 | 显示全部楼层

现在又出现一个问题,文件夹里面的CSS和JS都无法访问得到,都出现404,但文件是存在的,是怎么回事?

军哥运维代购:http://shop63846532.taobao.com/

发表于 2021-5-20 08:16:44 | 显示全部楼层

caiheqing 发表于 2021-5-18 14:36
谢谢军哥的回复,我重新修改了一下代码,现在有一个问题是http不能跳转到https,目录也一样,我把代码放 ...

你虚拟主机里都没添加带www的域名,肯定也就无法跳转了

你最前面就加了个301跳转,下面你写那么多if也是一个都不会匹配了,第一个return就已经结束不再进行下面的各种if了
 楼主| 发表于 2021-5-20 09:28:11 | 显示全部楼层

licess 发表于 2021-5-20 08:16
你虚拟主机里都没添加带www的域名,肯定也就无法跳转了

你最前面就加了个301跳转,下面你写那么多if也是 ...

谢谢军哥的回复,本来我是这样考虑,如果80端口我多写一个server,但测试配置文件会提示警告,现在server_name我加带www的,如果写一个return则显示此页面不能正确地重定向问题,这个真不知道怎么修改了,我是搬了服务器才显示这个问题,之前老服务器同样的配置没问题的,军哥,这个怎么修改
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2021-5-21 08:31:00 | 显示全部楼层

caiheqing 发表于 2021-5-20 09:28
谢谢军哥的回复,本来我是这样考虑,如果80端口我多写一个server,但测试配置文件会提示警告,现在server ...

上面贴出的配置文件除上面指出的外没有其他问题
有警告,说明其他配置文件是由问题的
如果使用了cdn,检查cdn上的设置
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-21 00:35 , Processed in 0.029016 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表