这是我的配置:
server {
server_name domain.com;
root /var/www/domain.com/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# 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/domain.com.error.log;
access_log /var/log/nginx/domain.com.access.log;
}
邮件网站有效,domain.com/
,但每当我打开domain.com/test/
之类的任何其他路由时,我都会收到500内部服务器错误。
此外,当我打开像domain.com/app_dev.php/test/
这样的开发环境时,我收到错误消息,说我无法访问app_dev.php
文件。
出了什么问题?
答案 0 :(得分:0)
试试这个:
server {
listen *:80;
server_name time.dev www.time.dev;
client_max_body_size 1m;
root /var/www/time/web;
index app_dev.php;
access_log /var/log/nginx/xxx_time.access.log;
error_log /var/log/nginx/xxx_time.error.log;
location ~ \.php$ {
root /var/www/time/web;
fastcgi_index app_dev.php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
try_files $uri $uri/ /app_dev.php$is_args$args;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APP_ENV dev;
}
location / {
root /var/www/time/web;
try_files $uri $uri/ /app_dev.php$is_args$args;
autoindex off;
index index.html index.htm index.php;
}
sendfile off;
}
它是从我的流浪汉机器中复制的。