相同Ip 不同端口 配置Nginx反向代理Apache(就是Nginx跳轉到Apache)
在linux 一經搭建好環境 先后安裝了Nginx 和Apache 由於 默認端口都是:80
一般客戶請求的服務器端口默認為80 所以Nginx作為靜態頁端口設置:80
Apache設置端口為:8080(在httpd.conf 文件中修改Listen:8080)
如何跳轉:
在nginx.conf中 添加
location / { proxy_pass http://202.85.224.166: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; }
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
這個兩句的作用是將客戶端ip轉發給apache服務器,就是apache獲得nginx服務器客戶端的ip 是真是的用戶ip.
好處是不用安裝apache的擴展包 mod_rpaf-0.6.tar.gz 了。很是方便。避免了編譯出錯也釋放了資源。
他們叫他:Nginx和Apache共存環境下apache獲得真實IP
代碼與
server {
listen 80;
server_name localhost;
}位置並列的
然后重新啟動服務器 瀏覽器輸入http://202.85.224.166:80; 看看是不是跳到Apache htdocs/index.html 頁面 而不是nginx的歡迎頁面
如果Apache重啟失敗怎么辦?
1查看端口 lsof -i:80
2關閉占用80端口的所有程序如
kill -9 5031
kill -9 5032
可能不止一個
3 然后重新啟動Apache
apache重新啟動命令:
/usr/local/apache2/bin/apachectl restart 重啟
linux kill用法、killall、pkill、xkill區別 http://www.2cto.com/os/201202/118483.html
基本的操作方法:
本文假設你的apahce安裝目錄為/usr/local/apache2,這些方法適合任何情況
apahce啟動命令:
推薦/usr/local/apache2/bin/apachectl start apaceh啟動
apache停止命令
/usr/local/apache2/bin/apachectl stop 停止
apache重新啟動命令:
/usr/local/apache2/bin/apachectl restart 重啟
要在重啟 Apache 服務器時不中斷當前的連接,則應運行:
/usr/local/sbin/apachectl graceful
如果apache安裝成為linux的服務的話,可以用以下命令操作:
service httpd start 啟動
service httpd restart 重新啟動
service httpd stop 停止服務
Linux系統為Ubuntu
一、Start Apache 2 Server /啟動apache服務
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start
二、 Restart Apache 2 Server /重啟apache服務
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
三、Stop Apache 2 Server /停止apache服務
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop