nginx重定向解決(rewrite or internal redirection cycle)
更新時間:2023年11月06日 09:56:17 作者:緣友一世
本文主要介紹了nginx重定向解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
錯誤日志和配置文件
訪問日志文件
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; } } }
問題分析
- 根據(jù)提供的訪問日志和nginx.conf配置文件分析,是循環(huán)重定向的問題。
- 配置中,location / 塊使用了
try_files $uri $uri/ /index.html;
會導(dǎo)致導(dǎo)致在嘗試訪問根目錄時發(fā)生重定向循環(huán)。 - 修改:添加一個新的
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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
為Node.js程序配置使用Nginx服務(wù)器的簡明教程
這篇文章主要介紹了為Node.js程序配置使用Nginx服務(wù)器的簡明教程,Nginx與Node自帶的服務(wù)器一樣都擁有非阻塞的高性能,需要的朋友可以參考下2016-01-01Nginx根據(jù)url中的path動態(tài)轉(zhuǎn)發(fā)到upstream的實現(xiàn)
這篇文章主要介紹了Nginx根據(jù)url中的path動態(tài)轉(zhuǎn)發(fā)到upstream的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01利用nginx搭建RTMP視頻點播、直播、HLS服務(wù)器
本文主要介紹了利用nginx搭建RTMP視頻點播、直播、HLS服務(wù)器,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05Nginx搭建RTMP流媒體服務(wù)器的實現(xiàn)
本文主要介紹了Nginx搭建RTMP流媒體服務(wù)器的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07