我想配置nginx的,並具有以下配置:NGINX服務器配置
/etc/nginx/sites-enabled/default
server {
server_name firstproj.dev www.firstproj.dev;
root /var/www/firstProj/web;
location/{
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
其中兩個app.php和app_dev.php是在/ var/WWW/firstProj/web文件/由symfony創建的文件夾,無需進一步修改。
firstProj是我目前工作的一個symfony項目,什麼我不明白這裏是:
爲什麼當我訪問www.firstproj.dev我得到
Oops! An Error Occurred The server returned a "500 Internal Server Error".
爲什麼當我訪問www.firstproj.dev/app_dev.php時,一切正常,我也可以訪問我的路線(例如:www.firstproj.dev/app_dev.php/homepage完美無缺,並返回我的行動的預期迴應控制器)
爲什麼當我訪問www.firstproj.dev/app.php時出現404錯誤。
我希望它與www.firstproj.dev/homepage沒有app_dev.php在那裏工作,但我不能讓這樣的。 此外,如果我訪問
我得到:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.
Thank you for using nginx.
我道歉,如果這是一個相當愚蠢的問題,但我是一個初學者就服務器的配置有關。
謝謝!
有你在等加firstproj.dev和www.firstproj.dev /主機? –
是的!它們都在/ etc/hosts文件中 –