跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • nginx 的重定向问题(小白提问)
未分類
5 11 月 2020

nginx 的重定向问题(小白提问)

nginx 的重定向问题(小白提问)

資深大佬 : kuanos 5

我自己弄了个 wordpress,用 nginx 配置两个不同的目录分别作为不同的站点,其中一个正常访问,另一个配置好了之后,ssl 也生效了,但是就是会显示重定向次数过多,我怀疑是强制 80 转 443 的问题,但是 nginx-t,以及 status 都没有报错。

小白找不到问题,求解答,非常感谢:

server {

listen 443 ssl;
listen 80;

server_name ABC.com www.ABC.com;
client_max_body_size 500m;

root /var/www/wordpress/;
index index.php index.html index.htm index.nginx-debian.html;

#if ($scheme = http ) {return 301 https://$host$request_uri;}

ssl_certificate /etc/letsencrypt/live/ABC.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ABC.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/ABC.com/chain.pem;
include snippets/ssl.conf;
return 301 https://ABC.com$request_uri;
include snippets/letsencrypt.conf;

location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~ /.ht {
deny all;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}

大佬有話說 (4)

  • 資深大佬 : jifengg

    你这不管三七二十一全部 return 301,能不重定向次数过多吗?
    我一个服务器是这么设置的:

    #设置域名跳转 https
    server{
    listen 80;
    server_name www.example.com;
    return 301 https://$host$request_uri;
    }

    80 和 443 端口监听分开,简单易懂

  • 資深大佬 : WeKeey

    server {
    listen 80;
    server_name xxx.xyz;
    return 301 https://xxx.xyz$request_uri;
    }

    server {
    listen 443 ssl;
    server_name xxx.xyz;

    ssl_certificate cert/xyz.xxx.crt;
    ssl_certificate_key cert/xyz.xxx.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
    proxy_pass http://zzz;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    access_log /var/log/nginx/xxx.access.log;
    }

  • 主 資深大佬 : kuanos

    @WeKeey @jifengg 感谢,已经解决了

  • 資深大佬 : quanjw

    你试试 497 状态码? 但是 我好像不行 也没找到原因、、、

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具