【发布时间】:2014-03-25 04:52:48
【问题描述】:
我不确定这个问题以前被回答过多少次,但我看到的每个答案都给出了解决这个问题的不同方法,但这些方法都没有奏效。我正在从 Apache 迁移到 Nginx,并且在设置它时遇到了一些严重的问题。我的 /etc/nginx/sites-available/default 看起来像这样...
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:Page Not Found 错误。该站点在 Apache 上运行良好,在花了将近 3-4 个小时解决这个问题后,我认为最好在这个论坛上寻求专家的建议。希望有人能帮我摆脱这种情况:(
【问题讨论】:
-
为什么 php 有 2 个位置?删除
location ~ /index.php/,如果你想location /doc没用,重新加载nginx再试一次 -
这个答案解决了我的问题。 stackoverflow.com/a/46188637/5554633
标签: codeigniter configuration nginx