2013-06-24 54 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