相同Ip 不同端口配置Nginx反向代理Apache

相同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

 

posted on 2014-07-28 23:04  < Angus >  阅读(3227)  评论(2编辑  收藏  举报

导航