mac osx使用80端口(使用nginx解决)

来源:互联网 发布:少数民族 知乎 编辑:程序博客网 时间:2024/05/17 09:28
起因:
     开发中,eclipse中无法使用80端口(因mac 本身已经占用了80端口),导致调试项目的时候,需要使用8080端口调试,不是很方便,所以,想到使用nginx做代理,然后做转发到8080端口。


思路:
     无非就那么几种:
          1、干掉80端口的占用程序,直接让tomcat占用
          2、端口转发,将80端口转发到其他端口上(mac上的ipfw)
          3、第三方的代理软件(eg:nginx)

纠结:
     前两种方式尝试了很多次,木有成功。。。。中间百度gogole了很多次,网上有很多文章介绍如何使mac开放80端口,但是。。。然并卵(PS:至少在我的电脑上木有管用),具体可以百度尝试。

解决办法:
     1、安装nginx
     2、设置nginx转发

具体步骤如下:(参考地址:http://blog.csdn.net/eagle_naixue/article/details/26063871)
1、Download latest PCRE. (地址:http://www.pcre.org/
2、安装
$ cd ~/Downloads $ tar xvzf pcre-8.5 $ cd pcre-8.5 $ sudo ./configure --prefix=/usr/local $ sudo make $ sudo make install 

安装Nginx

1、Download latest nginx from Nginx.org. (地址:http://nginx.org/
2、安装
$ cd ~/Downloads $ tar xvzf nginx-1.6.0.tar.gz $ cd nginx-1.6.0 $ sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-cc-opt="-Wno-deprecated-declarations" $ sudo make $ sudo make install 

开启Nginx

1、将/usr/local/nginx/sbin加入到环境变量里
2、运行
$ sudo nginx 
3、打开浏览器 http://localhost,如果看到如下界面表明nginx启动正常了
nginx.png
4、停止
$ sudo nginx -s stop

后面就是配置nginx,监听80端口,然后跳转到8080端口,
eg:

server {
listen 80;
server_name www.dutycode.com test.dutycode.com;
add_header Cache-Control private;
charset utf-8;
fastcgi_intercept_errors on;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_intercept_errors on;
}
}
浏览器输入www.dutycode.com即可看到结果

PS:
俺的博客:http://www.dutycode.com/mac_shiyong_80_duankou_nginx_jiejue.html
0 0