首先,我在计算机的系统文件夹中安装了 Winginx,非常徒劳..我很晚才意识到这一点。一切正常,直到我不得不在服务器上使用文件并将服务器移动到另一个位置。删除整个 WinGinx 文件夹,启用安装程序,在“C:\Winginx”中重新安装它。
我检查了本地主机,一切正常,添加了一个新项目,将文件从以前的服务器扔到那里,我得到“504 网关超时”。我忍受了很长时间的超时,设置fastcgi_connect_timeout 10;了它,但那是 10 秒的无用等待,在那之前我什至没有添加任何东西来使网站正常工作。
localhost/phpinfo.php 工作正常,但其他项目由于某种原因不运行 php 文件。默认情况下,localhost 没有自己的配置,我没有设置任何东西。任何项目都由除 .php 之外的所有文件加载。
连接时我在日志中收到以下错误:
[notice] 信号进程开始
[error] 16060#7760: *17 upstream timed out (10060: A connection attempt failed because the connected party didn't properly response after a period time, or established connection failed because connected host has failed respond) 连接上游时,客户端:127.0.0.1,服务器:我的域,请求:“GET/HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“我的域”
这是什么?上次一切都很好!而且,他说超时没有问题,这不可能。该站点未加载任何内容,上次我没有更改超时。另外,我将超时设置为 60 秒,这只是将等待时间拖到了 504 错误。
我在网上翻遍了这个主题,找到了有关 php-fpm 的信息,但我仍然不明白它是什么以及为什么,虽然很多人要求为此配置,但我没有任何地方,我查了一下一切。
nginx 配置中有一行:
fastcgi_pass localhost:9071;
站点配置中有类似的行:
fastcgi_pass 127.0.0.1:9000;
当我查看哪些端口在忙什么时,我注意到 9000 端口根本没有,而 9071 端口被 php-cgi.exe 进程占用了。(虽然默认应该是 9000 端口,我也没有改什么)。
我正在使用 Winginx,Windows 10,nginx 版本 1.12.0,PHP 版本 7.1.5。如果您需要任何其他信息 - 请询问,我不确定还应该提供什么来解决问题。
感谢您的关注!
站点配置如下所示,我什至没有更改它们:
server {
listen 127.0.0.1:80;
server_name music-portfolio.com www.music-portfolio.com;
root home/music-portfolio.com/public_html/;
index index.php index.html;
log_not_found off;
access_log logs/music-portfolio.com-access.log;
charset utf-8;
location ~ /\. { deny all; }
location = /favicon.ico { }
location = /robots.txt { }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
nginx.conf:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid temp/nginx.pid;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 55m;
#gzip on;
scgi_temp_path temp/uwsgi_temp 1 2;
uwsgi_temp_path temp/uwsgi_temp 1 2;
fastcgi_connect_timeout 1;
server {
listen 127.0.0.1:80;
root home/localhost/public_html;
index index.php index.html;
log_not_found off;
charset utf-8;
access_log logs/access.log main;
location ~ /\. {deny all;}
location / {
if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
root home/$2/public_html;
access_log logs/$2-access.log main;
}
}
location ~ \.php$ {
if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
root home/$2/public_html;
access_log logs/$2-access.log main;
}
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9071;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 127.0.0.1:443;
include ssl.conf;
root home/localhost/public_html;
index index.php index.html;
log_not_found off;
charset utf-8;
access_log logs/access.log main;
location ~ /\. {deny all;}
location / {
if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
root home/$2/public_html;
access_log logs/$2-access.log main;
}
}
location ~ \.php$ {
if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
root home/$2/public_html;
access_log logs/$2-access.log main;
}
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9071;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include tools-*.conf;
include vhosts/*.conf;
}
作为评论中讨论的结果。
系统的非常奇怪的行为。我建议将它重新排列为零
nginx并在配置中设置它fastcgi_pass 127.0.0.1:9071而不是127.0.0.1:9000. 显然 php 处理程序挂在端口 9071,而不是 9000。这里需要仔细查看端口。9071是7PHP的版本,看现在运行的是哪个版本,如果是5.6那么端口就是9056。
另一种选择,在 C:\Winginx\php56 或 php71(取决于版本)中,用记事本打开 php.ini 并取消注释 extension=php_mysql.dll 和 extension=php_mysqli.dll。同时,尝试访问 phpmyadmin 的 81 端口,如果 PHP 抱怨缺少 libmysql.dll,则下载并放到系统文件夹中,不要忘记重新启动整个程序集。
这似乎是最新版本的 Winginx 配置器中的行为。如果通过它创建域时,默认选择PHP,那么9000端口分配给fastcgi,如果选择php 7.1,那么9071端口其实很机智和方便,但可能值得通知用户这一点特征;)
虽然原则上,所有这些都可以在设置中看到:“设置”->“PHP 版本”-> 监听(IP:端口)= 127.0.0.1:9071
最新版本的Winginx不会自动安装php版本。您需要在项目设置中选择“Server Config”。在左侧,转到 PHP 部分并选择所需的版本。