[英]404 on existing file in codeigniter and nginx
我在帶有Nginx服務器的子文件夾中設置了codeigniter。
我在nginx中安裝了多個codeigniter,例如:
www.example.com/test
www.example.com/test1
我在測試目錄站點地圖中有一個文件夾。 當我訪問www.example.com/test/sitemap/sitemap.xml.gz
,出現404錯誤。
我的nginx文件是
server {
listen 80;
listen[::]: 80;
root / usr / share / nginx / html;
index index.php index.html index.htm;
server_name www.example.com;
access_log /
var / log / nginx / access.log;
error_log /
var / log / nginx / error.log error;
location / {
try_files $uri $uri / = 404;
}
location / test {
root / usr / share / nginx / html / test;
index index.html index.htm index.php;
try_files $uri $uri / /test/index.php;
location~ * ^ /(assets|files|robots\.txt) { }
}
location / test2 {
root / usr / share / nginx / html / test2;
index index.html index.htm index.php;
try_files $uri $uri / /test2/index.php;
}
error_page 404 / 404. html;
error_page 500 502 503 504 / 50 x.html;
location = /50x.html {
root / usr / share / nginx / html;
}
location~ * \.(ico | css | js | gif | jpe ? g | png | svg | woff2 | woff | ttf) $ {
expires max;
add_header Pragma public;
add_header Cache - Control "public, must-revalidate, proxy-revalidate";
}
location~ * ^ /(assets|files|robots\.txt) { }
location~/\.ht {
deny all;
}
location~\.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^ (. + \.php)(/.+)$;
fastcgi_pass unix: /var/run / php5 - fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;
}
}
您的按位置的root
指令可能是不必要的並且不正確。
通常,文檔根目錄是從周圍的server
塊繼承而來的,並且僅在location
塊中針對該上下文進行更改時才需要指定。
如果您的URI /test/index.php
位於/usr/share/nginx/html/test/index.php
,則root
的正確值是/usr/share/nginx/html
,無論它是否出現在server
塊或location
塊。
您當前正在指定路徑,例如: /usr/share/nginx/html/test/test/index.php
和/usr/share/nginx/html/test/test/sitemap/sitemap.xml.gz
。
您應該從location
塊中刪除root
語句,因為上面已經在server
塊中指定了正確的值。
有關詳細信息,請參見此文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.