2013-06-24 113 views
1

我是一个nginx新手,我得到了一个headeach服务器配置。 我将Nginx配置为Apache的反向代理,似乎都可以正常工作,但有时会出现错误500。Apache的Nginx反向代理 - 错误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是我的虚拟主机的IP地址。

谢谢大家的帮助!

+0

是由nginx的500错误,或者它被阿帕奇引起的,通过nginx的通过呢? –

+0

最后一天,当我仅通过浏览http:// site:8989来测试apache方面时,有时会出现错误。所以我认为它是由Apache引起的。 – user2514868

+0

我刚才也发现,**这个问题似乎出现在我运行fcgid模式时**。当我改用cgi模式时,这个问题似乎就出来了。 **但是当用cgi模式运行时,CPU负载会增加,这会使服务器很快拒绝请求** :-(。所以我必须回到fcgid模式,这个问题仍然没有解决 - 有时候内部服务器错误500。 – user2514868

回答

-1

我相信你会发现你的问题/var/log/.../abc.xyz.com_error_log文件

+0

谢谢!我已经尝试检查所有日志文件,但仍未找到。:-s – user2514868