相同Ip 不一样端口 配置Nginx反向代理Apache(就是Nginx跳转到Apache)php
在linux 一经搭建好环境 前后安装了Nginx 和Apache 因为 默认端口都是:80html
通常客户请求的服务器端口默认为80 因此Nginx做为静态页端口设置:80linux
Apache设置端口为:8080(在httpd.conf 文件中修改Listen:8080) nginx
如何跳转:apache
在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 了。非常方便。避免了编译出错也释放了资源。
代码与服务器
server {
listen 80;
server_name localhost;代理
}位置并列的rest
而后从新启动服务器 浏览器输入http://202.85.224.166:80; 看看是否是跳到Apache htdocs/index.html 页面 而不是nginx的欢迎页面server
若是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
1、Start Apache 2 Server /启动apache服务
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start
2、 Restart Apache 2 Server /重启apache服务
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
3、Stop Apache 2 Server /中止apache服务
# /etc/init.d/apache2 stopor$ sudo /etc/init.d/apache2 stop