nginx 的重定向问题(小白提问) - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kuanos
V2EX    问与答

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

  kuanos 2020 年 11 月 18 日 1756 次点击
这是一个创建于 1949 天前的主题,其中的信息可能已经有所发展或是发生改变。
我自己弄了个 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 条回复    2020-11-18 13:32:23 +08:00
jifengg
    1
jifengg  
   2020 年 11 月 18 日
你这不管三七二十一全部 return 301,能不重定向次数过多吗?
我一个服务器是这么设置的:

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

80 和 443 端口监听分开,简单易懂
WeKeey
    2
WeKeey  
   2020 年 11 月 18 日
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
    3
kuanos  
OP
   2020 年 11 月 18 日
@WeKeey @jifengg 感谢,已经解决了
quanjw
    4
quanjw  
   2020 年 11 月 18 日
你试试 497 状态码? 但是 我好像不行 也没找到原因、、、
关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2922 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 40ms UTC 02:11 PVG 10:11 LAX 19:11 JFK 22:11
Do have faith in what you're doing.
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86