我有一个带有nginx的虚拟服务器,我的Symfony项目安装在/var/www/test
中。在/etc/nginx/site-avalible/test.conf
我创建此配置:
server {
server_name test.dev www.test.dev;
root /var/www/test/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-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:/var/run/php5-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/test_error.log;
access_log /var/log/nginx/test_access.log;
}
然后创建符号链接:
ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf
并将规则添加到/etc/hosts
:
127.0.0.1 test.dev
这一切都在服务器上完成。然后我知道我的虚拟服务器的IP,并在/etc/hosts
中的本地计算机中创建:
82.91.183.61 test.dev
然后尝试在我的浏览器中打开但有502错误,为什么?如何更正nginx的虚拟主机配置?如果我知道IP并且可以创建虚拟主机,如何在本地计算机中打开我的项目?