我是 nginx 的新手,我对服务器配置感到头疼。我将 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;
}
}
阿帕奇配置:
# 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。
感谢大家的帮助!