我不知道這個問題之前已經回答了多少次,但我所看到的每個答案都給出瞭解決這些問題的方法,但都沒有解決這些問題。我正在從Apache遷移到Nginx,並且在設置時面臨一些嚴重問題。我的/ etc/nginx/sites-available/default看起來像這樣...Codeigniter nginx 404錯誤
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www/flo2go/;
index index.php index.html index.htm;
if ($request_filename !~ (js|css|images|robots\.txt|index\.php.*)) {
rewrite ^/(.*)$ /index.php/$1 last;
}
# Make site accessible from http://localhost/
server_name localhost;
location/{
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ /index.php/
{
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www/flo2go/index.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
我嘗試了一切,以使我的web應用程序工作。我一直收到的是404:找不到頁面錯誤。該網站在Apache上完美運行,花費了近3至4小時的時間解決了這個問題後,我認爲最好在此論壇上徵求專家意見。希望有人能保釋我擺脫這種局面:(
爲什麼2個位置爲php?刪除'location〜/ index.php /',如果你想'location/doc'沒用,請重新加載nginx並重試 –