linux下 nginx 转发内容至 本地 apache

本文详细介绍了如何配置Nginx作为反向代理,将流量从本地80端口转发至Apache的88端口,包括Nginx与Apache的配置文件设置,以及错误页面的管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

流量从本地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;

  

如果服务器配置较低则不推荐这么做

 

转载于:https://www.cnblogs.com/zyjfire/p/10136777.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值