【问题标题】:Nginx php files loading slowNginx php文件加载缓慢
【发布时间】:2016-03-18 18:10:43
【问题描述】:

编辑:我注意到你第一次访问它时速度很快,如果你关闭浏览器选项卡并重新访问它,它也会很快,但是如果你只是重新加载或在你有一个选项卡时访问它打开它很慢,真的很混乱。

今天我遇到了一个关于 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(本地主机)只有 index.html

localhost 加载速度非常快,但 example.com 加载速度非常慢,因为 php。

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;
}

example.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;
    }
}

【问题讨论】:

    标签: php apache batch-file nginx php-7


    【解决方案1】:

    我遇到了和你一样的问题。尝试更改您的 fastcgi_pass。

    从这里

    fastcgi_pass localhost:9054

    到这里

    fastcgi_pass 127.0.0.1:9054

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多