簡體   English   中英

Codeigniter和Nginx中現有文件上的404

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM