我尝试用Vagrant运行Symfony应用程序,我安装了Vagrant,将Symfony应用程序复制到Vagrant文件夹(vagrantrasmus/clientproject)中,我添加了hosts 192.168.7.7 clientproject
,并从conf.d添加了client.conf
server {
server_name clientproject;
root /vagrantrasmus/clientproject/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;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ '.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
但是,不工作,我收到了502 Bad Gateway
我修改了
中client.conf的内容server {
listen 80;
server_name localhost;
#root /var/www/default;
root /var/www/default/clientproject/web
index index.php index.html index.htm;
access_log /var/log/nginx/default-access.log main;
error_log /var/log/nginx/default-error.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/default;
}
location / {
#try_files $uri /app_dev.php$is_args$args;
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(.*)$ /index.php;
}
location ~ '.php {
include fastcgi_params;
fastcgi_keep_conn on;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+'.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
}
我有in logs
==> /var/log/nginx/default-error.log <==
2016/08/24 08:42:52 [error] 26472#0: *57 connect() to unix:/var/run/php-fpm.sock failed (111: Connection refused) while connecting to upstream, client: 192.168.7.1, server: clientproject, request: "GET /app_dev.php/translation HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "clientproject"
==> /var/log/nginx/default-access.log <==
192.168.7.1 - - [24/Aug/2016:08:42:52 +0000] "GET /app_dev.php/translation HTTP/1.1" 502 537 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "-"