我安装了Nginx来处理与apache一起的请求.以前,apache在端口80上监听,我现在切换到Nginx监听端口80和apache在一些不起眼的端口上,如果请求是非静态内容,则将Nginx proxy_pass发送到apache.
server { listen 80; server_name static.test.domain.com; location / { root /home/test/www/static; index index.html index.htm; } } server { listen 80; server_name domain.com *.domain.com; location / { proxy_set_header Server "testserver"; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8800; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/Nginx/html; } }
apache vhost配置具有以下内容:
NameVirtualHost *:8800 <VirtualHost *:8800> DocumentRoot /var/www/html ServerName domain.com ServerAlias www.domain.com </VirtualHost> <VirtualHost *:8800> DocumentRoot /home/test/www ServerName test.domain.com </VirtualHost> ...
我注意到请求现在更快但我也注意到Nginx出现在Server字段中的所有请求头中,即使请求是针对非静态页面的.这是一个潜在的问题吗?我见过一些服务器在同一个IP上使用Nginx,比如我的设置,但是服务器字段不同(如果是非静态内容请求,则显示Apache,静态时显示Nginx).
另外,我正在使用APC进行操作码缓存,并且我在我的站点目录中使用.htaccess和一些重定向规则(我想我需要将一些apache规则移植到Nginx?这是必要的吗?).我还有一些运行的Java cron脚本(这会阻碍Nginx进程吗?)这个新的设置会导致潜在的问题吗?
我知道很多问题.但提前谢谢!
更多信息:使用Nginx 1.0.6与apache 2.2在Centos 5 32bit上运行.
我的.htaccess文件(其中一些需要移植到apache吗?):
# BEGIN Compress text files <ifModule mod_deflate.c> <filesMatch "\.(css|js|x?html?|PHP)$"> SetoutputFilter DEFLATE </filesMatch> </ifModule> # END Compress text files # BEGIN Expire headers <ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType image/x-icon "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 604800 seconds" ExpiresByType application/javascript "access plus 604800 seconds" ExpiresByType application/x-javascript "access plus 604800 seconds" ExpiresByType application/xhtml+xml "access plus 600 seconds" </ifModule> # END Expire headers # BEGIN Cache-Control Headers <ifModule mod_headers.c> <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "max-age=2592000,public" </filesMatch> <filesMatch "\.(css)$"> Header set Cache-Control "max-age=604800,public" </filesMatch> <filesMatch "\.(js)$"> Header set Cache-Control "max-age=604800,private" </filesMatch> </ifModule> # END Cache-Control Headers # BEGIN Turn ETags Off <ifModule mod_headers.c> Header unset ETag </ifModule> FileETag None # END Turn ETags Off