编辑:我注意到你第一次访问它时速度很快,如果你关闭浏览器选项卡并重新访问它,它也会很快,但如果你只是重新加载或访问它当你打开它的选项卡时它会变慢,这真的很令人困惑。
今天我遇到了一个关于 PHP CGI 的问题,我是 nginx 的新手并且刚刚安装了它,当我注意到我也需要用它启动 PHP cgi 时,因为使用 IIS 它为我启动了它。 所以我在下面的批处理文件启动 php,但问题是......慢 PHP 文件,即使其中只有 html,它们加载速度也很慢。
@ECHO off
echo Starting PHP, please wait!
C:'nginx'php7'php-cgi.exe -b 127.0.0.1:9054 -c C:'nginx'php7'php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT
我对下面的批处理文件或nginx配置做错了什么吗?(我有 2 个配置)example.com 一个是带有.php文件的网站,nginx(本地主机)只有索引.html
本地主机加载速度超快,但由于 php,example.com 加载速度非常慢。
nginx.conf worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root C:'Users'Administrator'Dropbox'websites'local_website;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ '.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include vhosts/*.conf;
}
例子.com.conf
server {
listen ***.***.**.***:80;
server_name example.com www.example.com;
root C:'Users'Administrator'Dropbox'websites'php_website;
index index.php index.html;
log_not_found off;
charset utf-8;
#access_log logs/example.com-access.log main;
location ~ /'. {allow all;}
location / {
rewrite ^/(|/)$ /index.php?url=$1;
rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
rewrite ^/(.*)'.htm$ /$1.php;
}
location = /favicon.ico {
}
location = /robots.txt {
}
location ~ '.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我遇到了和你完全相同的问题。 尝试更改fastcgi_pass。
由此
fastcgi_pass 本地主机:9054
对此
fastcgi_pass 127.0.0.1:9054