由于项目必须要启动80端口,但是mac系统中非root用户无法直接使用1024以下的端口

2、释放apache的80端口

由于Mac OS是自带Apache服务的,它本身占用了80端口,首先你需要将Apache的监听端口改为其他端口或者将其直接卸载,我选用的是将其端口改为8011

1
sudo vim /etc/apache2/httpd.conf

Listen 8011

改动后,重启生效

1
sudo /usr/sbin/apachectl restart

到这里,你已经释放了80端口

3、使用Nginx分发80端口到8080端口

  1. 安装brew

见官网:https://brew.sh/index_zh-cn.html

  1. 使用Homebrew安装库

    1
    2
    brew search nginx
    brew install nginx
  2. 安装好了后,修改配置

    1
    sudo vim /usr/local/etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
listen 80;
server_name localhost l.sogou.com; 大专栏  MAC使用nginx分发80至8080端口/span>
#access_log logs/host.access.log main; location ~* ^/h5/{
proxy_pass http://127.0.0.1:8091;
} location ~* ^/weixin/{
proxy_pass http://127.0.0.1:8093;
} location ~* ^/api/{
proxy_pass http://127.0.0.1:8087;
} location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8080;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server下的结点:
listen:监听80端口
server_name:转发到哪个地址
proxy_pass:代理到哪个地址

  1. Nginx开机启动

你需要了解的就是plist文件。plist就是property list format的意思,是苹果用来保存应用数据的格式,其实就是个xml。
可以在/usr/local/opt/nginx 下找到nginx对应的plist文件,比如在作者电脑上是 homebrew.mxcl.nginx.plist 。

需要把这个文件复制到 /Library/LaunchDaemons 下,系统启动时启动。
也可以复制到 /Library/LaunchAgents下,在用户登录时启动。
接着执行launchctl load -w,如下:

1
2
3
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

最后,重启你的机器,你会发现nginx在80端口启动了,试着通过http://localhost直接访问

  1. 修改配置 重启生效
    1
    2
    3
    4
    sudo vim /usr/local/etc/nginx/nginx.conf
    
    cd /usr/local/opt/nginx/bin/
    sudo ./nginx -s reload

MAC使用nginx分发80至8080端口的更多相关文章

  1. 电信固定ip宽带80与8080端口踩坑

    本文只是作为记录,避免后面遇到此类问题耗费时间. 实际情况:公司有个固定电信宽带是固定IP的,想把固定IP映射到测试环境ip,实现可以公网通过固定ip访问,内网通过局域网ip访问. 测试环境服务是占用 ...

  2. ISP封了80和8080端口

    今天用自己的电脑做服务器,绑定了域名,路由映射什么的都做了,但是80和8080端口在外网怎么都访问不了,只在内网可以访问. 最后看有人说联通封了80和8080端口,真是遗憾,谨记于此,以后有时间了再来 ...

  3. tomcat、Apache服务器外网无法访问80和8080端口,其他端口可以访问

    tomcat.Apache服务器外网无法访问80和8080端口,其他端口都可以访问,很明显地看出这是网络运营商的问题,他们把80和8080端口对外访问屏蔽了. 解释:这两个端口是常用的HTTP协议端口 ...

  4. CentOS/Linux 开放80、8080端口或者开放某个端口

    装载系统的时候只开启了22端口.结果再装完Nginx+php+mysql 后不能访问网站. iptables -L -n 查看防火墙设置发现没开启80端口 由于Linux防火墙默认是关闭的.可以用两种 ...

  5. Linux开放80、8080端口或者开放某个端口

    装载系统的时候只开启了22端口.结果再装完Nginx+php+mysql 后不能访问网站. 查看防火墙设置发现没开启80端口 iptables -L -n 由于Linux防火墙默认是关闭的.可以用两种 ...

  6. centos7开启80和8080端口

    开启8080端口 firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --reload 重定向80端口到8080端口firewall-c ...

  7. Ubuntu16.04中nginx除80之外其他端口不能访问

    不废话, 大多数都以为是ufw防火墙的问题. 但我的是因iptables防火墙, 坑死我了. 查了好多也没查到怎么在Ubuntu关闭iptables, 索性直接卸载 apt-get remove ip ...

  8. mac下8080端口到80端口的转发

    MAC OS 本质上还是 Unix 系统, Unix 系统大多默认情况下非root用户是无法使用小于1024的常用端口的.这时候如果你开发中需要在普通用户下用到80端口, 比如 tomcat, 比如 ...

  9. Mac OS X 绑定80端口,不装nginx的小技巧

    Mac OS X 因为要绑定80端口需要ROOT权限, 但是如果用root权限启动eclipse或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除. 为此, 我们可以通过pfc ...

随机推荐

  1. maven隐含依赖

    1.有时候,我们在pom.xml依赖了2个jar包,不过在工程lib里看到依赖包多于2个,这是为什么呢?原因是maven引入一个jar时,会连带引入这个jar包依赖的jar包,除非在配置引入这个jar ...

  2. flash插件的安装——网页视频无法播放

    1.从官网下载Adobe flash player 安装包.官方网址:https://get.adobe.com/cn/flashplayer/ 或者从我的网盘下载:链接:https://pan.ba ...

  3. redis数据库写入数据时提示redis.exceptions.ResponseError错误

    今天运行Django项目在redis数据库写入数据时提示如下错误: ERROR log 228 Internal Server Error: /image_code/cf9ccd75-d274-45c ...

  4. [LC] 1007. Minimum Domino Rotations For Equal Row

    In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino.  (A domi ...

  5. P2486 [SDOI2011]染色 区间合并+树链剖分(加深对线段树的理解)

    #include<bits/stdc++.h> using namespace std; ; struct node{ int l,r,cnt,lazy; node(,,,):l(l1), ...

  6. mysql关键字汇总

    ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH BY CALL CASCADE C ...

  7. 系统学习Javaweb8----JavaScript4(结束)

    学习内容: 1.DOM对象 1.2DOM对象--元素对象常见属性 2.JS事件 2.1JS事件--入门案例 2.2JS事件--驱动机制 2.3常见JS事件--点击事件 2.4常见JS事件--点击事件 ...

  8. cs231n spring 2017 lecture15 Efficient Methods and Hardware for Deep Learning

    讲课嘉宾是Song Han,个人主页 Stanford:https://stanford.edu/~songhan/:MIT:https://mtlsites.mit.edu/songhan/. 1. ...

  9. spring的事务,详解@Transactional

    事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持. Spring 事务管理分为编程式和声明式的两种方式. 编程式事务指的是通过编码方式实现事务,编程式事务管理使用 ...

  10. whatsoever|

    ADV (用于名词词组后,强调否定陈述)丝毫,任何,无论什么You use whatsoever after a noun group in order to emphasize a negative ...