1.首先修改apache服務器的配置文件/etc/apache2/sites-available/000-default.conf
2.找到這段代碼<VirtualHost *:80>,將其修改成你所希望代理的apache服務器端口,例如:<VirtualHost *:8080>
如果想多添加apache的端口可以添加如下代碼(用於二級域名綁定love.domain.com):
<VirtualHost *:6060>
DocumentRoot /var/www/love
</VirtualHost>
同時也要修改apache服務器監聽的端口號
將/etc/apache2/ports.conf修改成Listen 8080
3.修改nginx服務器的配置文件/etc/nginx/sites-available/default,添加如下代碼即可
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
4.重啓apache和nginx服務器
/etc/init.d/apache2 restart
/etc/init.d/nginx restart