Nginx 虚拟主机,site1 正常运行,但 site2 收到 504 网关超时错误

Nginx 虚拟主机,site1 正常运行,但 site2 收到 504 网关超时错误
  • Ubuntu 14.10
  • Nginx 1.6.2
  • 运行 PHP5-FPM
  • 两个网站都是 Wordpress
  • 这两个文件都符号链接到 /etc/nginx/sites-enabled 目录
  • 已重新启动整个服务器,并运行服务 nginx 重启服务 php5-fpm 重启

Site1 运行良好

Site2 尝试加载,但停留在“正在等待 site2.com....”状态,直到出现 504 网关超时

配置如下(这是 sites-available 和 sites-enabled 中仅有的 2 个文件)

网站1.com

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/site1.com;
    index index.php index.html index.htm;

    server_name site1.com *.site1.com;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
     }

}

site2.com

server {
    listen 80;
    listen [::]:80;

    root /var/www/site2.com;
    index index.php index.html index.htm;

    server_name site2.com *.site2.com;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
     }

}

nginx.conf

    user www-data;
    worker_processes 4;
    pid /run/nginx.pid;

    events {
            worker_connections 4096;
            multi_accept on;
    }

    http {

            ##
            # Basic Settings
            ##

            #sendfile on;
            #tcp_nopush on;
            #tcp_nodelay on;
            #keepalive_timeout 10;
            types_hash_max_size 2048;
            server_tokens off;

            # server_names_hash_bucket_size 64;
            # server_name_in_redirect off;

            include /etc/nginx/mime.types;
            default_type application/octet-stream;

    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";

    ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;


            ##
            # Logging Settings
            ##
    access_log off;
    log_not_found off;
    error_log /var/log/nginx-error.log warn;
            #access_log /var/log/nginx/access.log;
            #error_log /var/log/nginx/error.log;

            ##
            # Gzip Settings
            ##

            gzip on;
            gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    open_file_cache max=2000 inactive=20s;
    open_file_cache_valid 60s;
    open_file_cache_min_uses 5;
    open_file_cache_errors off;
    client_max_body_size 50M;
    client_body_buffer_size 1m;
    client_body_timeout 15;
    client_header_timeout 15;
    keepalive_timeout 2 2;
    send_timeout 15;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    fastcgi_buffers 256 16k;
    fastcgi_buffer_size 128k;
    fastcgi_connect_timeout 10s;
    fastcgi_send_timeout 120s;
    fastcgi_read_timeout 120s;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    reset_timedout_connection on;
    server_names_hash_bucket_size 100;

答案1

需要检查以下几点:

  • 检查 nginx 访问/错误日志
  • 检查 php5-fpm 日志和系统日志消息 - 也许您的 site2.com 只是因为 php5 脚本超时而死机(您在 php 中设置的超时时间很短,脚本可能需要一些时间来处理一些文件,重建缓存)
  • 检查你的电脑上的 DNS 是否正确解析 site1.com 和 site2.com,以及它们是否指向正确的 DNS 条目

  • 使用 curl 对给定的服务器 IP(您使用的服务器)执行 GET 请求,并尝试设置 HEADER 来为 site1.com 和 site2.com 指定 vhost,看看它是否有效 - 首先从服务器本身尝试,然后从远程机器尝试。示例https://stackoverflow.com/questions/356705/how-to-send-a-header-using-a-http-request-through-a-curl-call

  • 检查对 site1.com 的大量请求是否不会使 php5-fpm 工作器饱和 - 可以通过在每个网站中创建不同的 php5-fpm 池来避免这种情况

相关内容