nginx重定向解決(rewrite or internal redirection cycle)
錯(cuò)誤日志和配置文件
訪問(wèn)日志文件
2023/10/15 07:13:48 [error] 30#30: *1 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 123.55.159.97, server: server_name, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx" 123.55.159.97 - - [15/Oct/2023:07:13:48 +0000] "GET / HTTP/1.1" 500 579 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46" 123.55.159.97 - - [15/Oct/2023:07:13:48 +0000] "GET /favicon.ico HTTP/1.1" 500 579 "http:///" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46" 2023/10/15 07:13:48 [error] 30#30: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 123.55.159.97, server: server_name, request: "GET /favicon.ico HTTP/1.1", host: "xxx.xxx.xxx.xxx", referrer: "http://xxx.xxx.xxx.xxx/"
nginx.conf配置文件內(nèi)容
events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 50m; client_body_buffer_size 10m; client_header_timeout 1m; client_body_timeout 1m; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 4; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; server { listen 80; server_name my_server_name; location / { root /usr/local/xxx_vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location ^~ /api/ { proxy_pass http://xxx.xxx.xxx.xxx:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
問(wèn)題分析
- 根據(jù)提供的訪問(wèn)日志和nginx.conf配置文件分析,是循環(huán)重定向的問(wèn)題。
- 配置中,location / 塊使用了
try_files $uri $uri/ /index.html;
會(huì)導(dǎo)致導(dǎo)致在嘗試訪問(wèn)根目錄時(shí)發(fā)生重定向循環(huán)。 - 修改:添加一個(gè)新的
location=/index
塊,直接提供 /index.html 而不進(jìn)行重定向。
server { listen 80; server_name my_server_name; location / { root /usr/local/xxx_vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location = /index.html { root /usr/local/xxx_vue; } location ^~ /api/ { proxy_pass http://xxx.xxx.xxx.xxx:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
- 使用以下命令重新加載Nginx,即可生效
sudo nginx -s reload
到此這篇關(guān)于nginx重定向解決(rewrite or internal redirection cycle)的文章就介紹到這了,更多相關(guān)nginx重定向 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- nginx 老網(wǎng)站域名重定向到新網(wǎng)站的方法(親測(cè))
- 在Nginx中實(shí)現(xiàn)URL重寫(xiě)與重定向
- Nginx地址重定向的實(shí)現(xiàn)
- nginx的服務(wù)配置及重定向問(wèn)題
- nginx重寫(xiě)和重定向關(guān)系與配置方式
- Nginx重定向后請(qǐng)求參數(shù)丟失的原因分析及解決方案
- nginx反向代理后無(wú)限重定向的問(wèn)題解決方法
- Nginx中rewrite(地址重定向)的深入剖析
- 利用Nginx實(shí)現(xiàn)URL重定向的簡(jiǎn)單方法
- 配置nginx 重定向到系統(tǒng)維護(hù)頁(yè)面
- nginx中重定向的實(shí)現(xiàn)
相關(guān)文章
為Node.js程序配置使用Nginx服務(wù)器的簡(jiǎn)明教程
這篇文章主要介紹了為Node.js程序配置使用Nginx服務(wù)器的簡(jiǎn)明教程,Nginx與Node自帶的服務(wù)器一樣都擁有非阻塞的高性能,需要的朋友可以參考下2016-01-01Nginx根據(jù)url中的path動(dòng)態(tài)轉(zhuǎn)發(fā)到upstream的實(shí)現(xiàn)
這篇文章主要介紹了Nginx根據(jù)url中的path動(dòng)態(tài)轉(zhuǎn)發(fā)到upstream的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01利用nginx搭建RTMP視頻點(diǎn)播、直播、HLS服務(wù)器
本文主要介紹了利用nginx搭建RTMP視頻點(diǎn)播、直播、HLS服務(wù)器,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05Nginx搭建RTMP流媒體服務(wù)器的實(shí)現(xiàn)
本文主要介紹了Nginx搭建RTMP流媒體服務(wù)器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07nginx 某些url只能由特定網(wǎng)段訪問(wèn)
在一些場(chǎng)景中,我們需要根據(jù)客戶端的IP地址或網(wǎng)段對(duì)訪問(wèn)進(jìn)行控制,在Nginx中針對(duì)某些URL只允許特定網(wǎng)段訪問(wèn),本文就來(lái)介紹一下如何實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09