Nginx + hhvm + mysql:第一次请求超时或等待很长时间

时间:2015-03-06 15:55:45

标签: nginx hhvm

一个非常奇怪的问题:

我的网站是典型的Linux + hhvm + nginx + mysql网站,当我打开我的网站时,会发生以下情况:

  1. 输入地址,按回车。
  2. 长时间等待回复,有时我甚至会超时。
  3. 如果我在第一阶段点击进入后立即点击刷新,则网站会顺利加载。
  4. 问题出在哪里?

    这是我的nginx配置:

    server {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
    include /var/www/xxx/nginx.conf;
        root /var/www/xxx;
        index index.php index.html index.htm;
    
        server_name xxx.xxx
        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }
    
    #fastcgi_cache start
    set $no_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $no_cache 1;
    }   
    if ($query_string != "") {
        set $no_cache 1;
    }   
    
    # Don't cache uris containing the following segments
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
            set $no_cache 1;
    }   
    
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $no_cache 1;
    } 
    
    
    
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; log_not_found off; expires max;
    }
    
        error_page 404 /404.html;
    
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_cache_bypass $no_cache;
    fastcgi_no_cache $no_cache;
    fastcgi_cache  microcache;
    fastcgi_cache_key $scheme$host$request_uri$request_method;
    fastcgi_cache_valid 200 301 302 30s;
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    }
    

1 个答案:

答案 0 :(得分:0)

在我的HHVM server.ini中添加了以下内容。如果您的服务器是本地或远程服务器,则需要将其更改为指向MySQL套接字。 您可以使用

查看服务器套接字的位置
  

cat /etc/mysql/my.cnf

在Mariadb jessie的例子是/var/run/mysqld/mysqld.sock

在server.ini中添加示例:

  

hhvm.mysql.socket = /var/run/mysqld/mysqld.sock