我为我的新项目设置了一个PHP7-LEMP-Vagrant框。我之前使用的是Apache,所以我需要翻译将所有不存在的文件重定向到index.php的规则。我在/ etc / nginx / sites-available / mysite中执行了以下操作:
location / {
try_files $uri $uri/ /index.php?$args;
}
添加此内容并重新启动nginx后,我可以访问我的网站一次,可能导航到另一个网站,但随后所有后续请求都将超时。我首先调用哪个URL并不重要,我可以调用任何一次URL。
/var/log/nginx/error.log:
[error] 21885#21885: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.13.1, server: myserver.dev, request: "GET /user/me HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "myserver.dev", referrer: "http://myserver.dev/"
/etc/php/7.0/fpm/php-fpm.conf :这里没什么有趣的。
网站配置文件:
server {
listen 80;
server_name myserver.dev;
root /vagrant/public_html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
有什么想法吗?