Ubuntu Apache 和nginx 配合使用
一、使用思路
將nginx作爲代理服務器和web服務器使用,設置nginx的監聽端口爲80,設置Apache的監聽端口爲80以外的端口,我這暫時使用15266端口。這樣設置後,nginx充當客戶端訪問時的代理服務器,發揮其併發的優勢;Apache充當後端處理模塊,發揮其模塊多,方便處理動態請求問題。
處理思路如下:(轉自https://blog.csdn.net/ITYang_/article/details/53907937)
二、修改Apache配置
1、修改監聽端口配置
sudo vim /etc/apache2/ports.conf
sudo vim /etc/apache2/ports.conf
將上述listener port 改爲自己要的監聽端口,如:5266
三、修改nginx配置
1、修改監聽端口
sudo vim /etc/nginx/nginx.conf
在nginx.conf的 http內添加如下內容:
server {
listen 80;
server_name www.one.ityangs.cn one.ityangs.cn ;
location / {
proxy_pass http://127.0.0.1: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;
}
}
四、重啓服務
1、重啓Apache服務
sudo /etc/init.d/apache2 restart
2、開放防火牆的端口
sudo ufw allow 5266
sudo iptables -I INPUT -p TCP --dport 5266 -j ACCEPT
3、重啓nginx服務
/etc/init.d/nginx {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}
或
nginx -c /usr/local/nginx/conf/nginx.conf
配置完畢,開心配置別的去吧!