nginx+apache 新增vhost并新增端口
生产环境为 nginx + apache
nginx
1. 提供静态主页的WEB服务
2. 通过反向代理访问apache里的服务
lampp的apache
提供后端服务功能
现在要在尽量不改动后端的基础上,临时性的把静态主页换成PHP的一套主页。
首先找到apache的httpd.conf文件
把
#Include etc/extra/httpd-vhosts.conf
的注释去掉
然后编辑httpd-vhosts.conf
增加
Listen 8090 #指定vhost的端口,避免跟原来的服务端口冲突
<VirtualHost *:8090>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/opt/lampp/htdocs_mall" #指定新目录
ServerName localhost
</VirtualHost>
#一定要对新目录进行访问权限设置
<Directory "/opt/lampp/htdocs_mall">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
然后修改nginx的配置文件
在原来的主页配置里增加一条
proxy_pass
location / {
root /opt/nginx/html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8090;
}
重启 apache,nginx就可以了。
本文档详细介绍了如何在Nginx+Apache生产环境中,不改动后端服务的基础上,临时将静态主页替换为PHP主页。主要步骤包括:解除Apache httpd.conf中vhosts配置的注释,新增监听端口和VirtualHost配置,设置新目录访问权限;在Nginx配置中添加反向代理规则,将请求转发至Apache的特定端口。完成配置后,重启两服务即可实现切换。
679

被折叠的 条评论
为什么被折叠?



