Nginx反向代理apache及Nginx

一. 代理apahce:

  1.先配置nginx配置文件:

[root@centos7 conf.d]# vim /opt/app/nginx/conf.d/wordpress.conf

server {

   listen       80;

   server_name  localhost;

   location / {

   proxy_pass http://192.168.1.204;

   proxy_set_header X-Real-IP  $remote_addr;

   }

}

2.若apache需要看到客戶端真是IP,需要修改配置文件.

vim /etc/httpd/conf/httpd.conf

LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" 

原來的%h改成{X-Real-IP}i ,這裏日誌裏就客戶端訪問IP了.


二.nginx方面.

   簡單方便.深入的需要看官方文檔.

[root@centos7 conf.d]# cat /opt/app/nginx/conf.d/wordpress.conf 

server {

   listen       80;

   server_name  localhost;


   location / {

   proxy_pass http://192.168.1.204;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

   }

}

  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章