Apache的Nginx反向代理 - 有时会出现错误500

时间:2013-06-24 04:33:40

标签: apache nginx

我是nginx的新手,我得到了服务器配置的headeach。 我将Nginx配置为Apache的反向代理,一切似乎都正常,但有时错误500出现。

这里奇怪的是,看到错误500消息后,我刷新页面并且工作!错误500看起来非常快,只有一半秒,所以我不认为这是超时问题。

当我测试浏览服务器上的网站和网页时,这个问题是随机出现的。

在任何地方搜索并尝试更改配置但未找到它,所以希望大家都能提供帮助。

以下是配置: 主要的nginx配置 - nginx.conf:

####################
# nginx.conf
####################

user              nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 30000;

events {
    worker_connections  8192;
    use epoll;
}

http {
    server_tokens off;
    include       /etc/nginx/mime.types;

    # proxy settings
    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size    20m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffering     off;

    index    index.html index.htm index.php;
    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  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    server_names_hash_bucket_size 128;
    tcp_nodelay     off;

    #keepalive_timeout  0;
    keepalive_timeout  5;

    ## Gzip Compression
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 5;
    gzip_proxied any;
    gzip_min_length  256;
    #gzip_buffers 32 4k;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/xml+rss application/javascript application/json;
    # Some version of IE 6 don't handle compression well on some mime-types, 
    # so just disable for them
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    # Set a vary header so downstream proxies don't send cached gzipped 
    # content to IE6
    gzip_vary on;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
}

默认服务器配置:

#
# The default server conf.d/default.conf
#
server {
    listen       80;
    server_name  _;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        proxy_pass   http://127.0.0.1:8989;
    }
}

具有上述问题的服务器 - /conf.d/myvhost.conf:

server {
    listen       IP:80; ssl off;
    server_name  abc.xyz.com;

    access_log  /home/myvhost/logs/nginx_access.log;
    error_log  /home/myvhost/logs/nginx_error.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_buffering off;

      proxy_pass   http://IP:8989;
    }

    location ~* ^.+\.(htm|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|avi|mp4|mp3|ogg|flv)$ {
      expires 14d;
      add_header Pragma public;
      add_header Cache-Control "public, must-revalidate, proxy-revalidate";
      root /home/myvhost/public_html;
    }

    location ~ /\.ht {
        deny  all;
    }

}

apache配置:

# httpd.conf
# general
...

# virtual host
<VirtualHost IP:8989>
SuexecUserGroup "#503" "#503"
ServerName abc.xyz.com
DocumentRoot /home/myvhost/public_html
ErrorLog /var/log/.../abc.xyz.com_error_log
CustomLog /var/log/.../abc.xyz.com_access_log combined
ScriptAlias /cgi-bin/ /home/myvhost/cgi-bin/
ScriptAlias /awstats/ /home/myvhost/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/myvhost/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/myvhost/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/myvhost/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/myvhost/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.abc.xyz.com
RewriteRule ^(.*) https://abc.xyz.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.abc.xyz.com
RemoveHandler .php
RemoveHandler .php5
<Files awstats.pl>
AuthName "abc.xyz.com statistics"
AuthType Basic
AuthUserFile /home/myvhost/.awstats-htpasswd
require valid-user
</Files>
IPCCommTimeout 121
</VirtualHost>

在我粘贴的所有配置中, IP 是我的vhost&#39;

感谢大家的帮助!

1 个答案:

答案 0 :(得分:-1)

我相信你会在/var/log/.../abc.xyz.com_error_log文件中找到你的问题