由于项目必须要启动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. 14 微服务电商【黑马乐优商城】:day02-springcloud(理论篇二:知道什么是SpringCloud)

    本项目的笔记和资料的Download,请点击这一句话自行获取. day01-springboot(理论篇) :day01-springboot(实践篇) day02-springcloud(理论篇一: ...

  2. BTree非递归

    preorder void PreOrder(BTNode* b) { BTNode* p = b; SqStack* st; InitStack(st); if (b != NULL) { Push ...

  3. Django中间件-跨站请求伪造-django请求生命周期-Auth模块-seettings实现可插拔配置(设计思想)

    Django中间件 一.什么是中间件 django中间件就是类似于django的保安;请求来的时候需要先经过中间件,才能到达django后端(url,views,models,templates), ...

  4. We don't wanna work!

    We don't wanna work! [JAG Asia 2016] 两个set,一个代表工作的,一个代表不工作的 其实是一个很简单的模拟,但是我竟然排序之前标号.... 检查代码的时候要从头开始 ...

  5. auth模块用法

    Auth模块: 如果你想用auth模块   那么你就用全套 createsuperuser  创建超级用户 这个超级用户就可以拥有登陆django admin后台管理的权限 Auth模块是Django ...

  6. ByteCode Instrumentation

    Bytecode Instrumentation 定义 我们首先来看看,什么叫"Instrumentation"?Instrumentation这个词有很多意思,在维基百科中,它是 ...

  7. numpy矩阵运算--矩阵乘法

    1)元素对应相乘,使用 multiply 函数或 * 运算符来实现 a = np.array([2,2,2])b = np.array([3,3,3]) c1 = a*a c1 array([4, 4 ...

  8. Leetcode13_罗马数字转整数

    题目 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的 1. ...

  9. OpenCV 使用FLANN进行特征点匹配

    #include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #inclu ...

  10. Sampling Distribution of the Sample Mean|Central Limit Theorem

    7.3 The Sampling Distribution of the Sample Mean population:1000:Scale are normally distributed with ...