流量从本地80端口的nginx进来之后在转发给本地apache的88端口,在什么环境下会用到这种配置还有待观察,这里先做个记录
先配置 nginx 的配置文件 xxx.conf 如图
server {
listen 80;
server_name xxxx.com www.xxx.com;
root /www/xxx;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location / {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
接下来在配置 apache
<VirtualHost *:88>
DocumentRoot /www/xxxx
ServerName xxxx.com
ServerAlias www.xxxx.com
ErrorDocument 400 /errpage/400.html
ErrorDocument 403 /errpage/403.html
ErrorDocument 404 /errpage/404.html
php_admin_value open_basedir /www/xxxx:/tmp
<IfModule mod_deflate.c>
DeflateCompressionLevel 7
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js html htm gif jpg png bmp php
</IfModule>
</VirtualHost>
<Directory /www/xxxx>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
再分别重启 apache 和 nginx 即可
下图是naproxy.conf的配置图
proxy_connect_timeout 30s;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
如果服务器配置较低则不推荐这么做