使用 fastcgi 使用 nginx 路由 php 请求会导致 404 错误



我是nginx的新手,想要对其进行配置,以便用户可以访问诸如

http://[ip_address]/dev/index.php/customer/account/login/

我认为这可能与使用FastCGI处理请求并将其传递给Magento有关。但是,每当我访问它时,我都会看到一条 404 消息。我可以确认运行nginx并拥有目录和文件的用户是www-data。所以它可以访问它。我需要帮助正确配置 nginx 和 FastCGI,以便请求加载正确的页面。 我的所有应用程序都在dev/文件夹中。以下是/etc/nginx/sites-available/defaul 中默认文件的相关块:

root /var/www;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _ test.xxx.com;

location /dev/ {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php$is_args$args;
}
location /dev/app/ {
deny all;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}

这是我的nginx配置。可能对你有所帮助。

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_read_timeout 900;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}

最新更新