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就可以了。