【发布时间】:2018-10-25 21:03:57
【问题描述】:
我想用 nginx 设置 symfony,这个配置工作正常
server {
listen 80;
root /src/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
但是我也希望在我的服务器上我也应该能够通过 app_dev.php 和 app_test.php 访问文件
到目前为止,上面的配置。 http://127.0.0.1/api/check 工作正常
但我也想要
http://127.0.0.1/app_dev.php/api/check 和 http://127.0.0.1/app_test.php/api/check 也可以正常工作。
目前它给了我 404 错误
【问题讨论】:
-
它是否适用于
http://127.0.0.1/app.php/api/check? -
@Phil 不,它不起作用,因为看起来所有的 url 都自动以 app.php
try_files $uri /app.php$is_args$args;为前缀。我尝试将其更改为 app_dev 和 app_test,它也可以正常工作,但它们不能一起工作,使用 apache2 可以工作,鞠躬现在我只想使用 nginx -
您可能需要添加
fastcgi_param PATH_INFO $fastcgi_path_info;。见nginx.com/resources/wiki/start/topics/examples/phpfcgi/…。您还没有为app.php以外的任何东西启用 php-fpm -
@Phil 你的意思是,我需要删除行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;并使用fastcgi_param PATH_INFO $fastcgi_path_info;,我也尝试将正则表达式更改为使用 app_dev 但仍然出现 404 错误 -
老实说,我不知道,因为我是一个糟糕的系统管理员。如果您无法在此处获得答案,您可能会在 serverfault.com 获得一些关注。
标签: php symfony nginx ubuntu-16.04 fpm