簡體   English   中英

Nginx php文件加載緩慢

[英]Nginx php files loading slow

編輯:我注意到您第一次訪問它時速度很快,如果您關閉瀏覽器選項卡並重新訪問它,它也會很快,但是如果您只是在打開一個選項卡時重新加載或訪問它,它就會去慢,真的很混亂。

今天我遇到了一個關於 PHP CGI 的問題,我是 nginx 的新手並且剛剛安裝了它,當我注意到我也需要用它啟動 PHP cgi 時,因為它為我啟動了它。 所以我用下面的批處理文件啟動 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

本地主機加載速度非常快,但由於 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM