解决方案 主要思路就是配置Nginx,将要访问的域名:80 转发至 启动的域名+启动的端口号,如wyb-qa.guahao-test.com 转发至 wyb-qa.guahao-test.com:8000

nginx的配置如下:

  1. vim /usr/local/etc/nginx/nginx.conf
  1. server {
  2. listen 80;
  3. server_name wyb-qa.guahao-test.com;
  4. # proxy_set_header Cookie $http_cookie;
  5. location / {
  6. # proxy_set_header Host $http_host;
  7. proxy_set_header X-Real-IP $remote_addr;
  8. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9. proxy_set_header Whatis-Scheme $scheme;
  10. proxy_set_header Whatis-Host $http_host;
  11. proxy_pass http://127.0.0.1:8000;
  12. }
  13. }

mac查看80端口是否被占用

  1. lsof -i:80

接下来的问题就是如何在mac上安装nginx
安装nginx 需要先安装 brew
那么如何安装brew呢:
优先参考此文章

  1. /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

不行的话再参考以下步骤

参考此文章
具体步骤如下:

  1. 如果是已有brew 可先卸载:

    1. /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"
  2. 卸载后再安装 ```bash

    1.执行安装脚本

    export HOMEBREW_BREW_GIT_REMOTE=”https://mirrors.ustc.edu.cn/brew.git“ export HOMEBREW_CORE_GIT_REMOTE=”https://mirrors.ustc.edu.cn/homebrew-core.git“ /bin/bash -c “$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)”

2.安装完成后设置

echo ‘export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles‘ >> ~/.zprofile source ~/.zprofile

  1. brew安装成功后,那就开始安装nginx
  2. ```bash
  3. brew install nginx

在安装nginx的过程中可能会遇到一些包下载不了的问题,需要配置host:
具体需要看日志看看哪些域名是404,比如我这次安装过程过程中就是github.com 和 raw.githubusercontent.com这两个域名下的包下载不了,那么就需要去该网站查看其对应的ip,然后再配置host

  1. 140.82.112.3 github.com
  2. 185.199.111.133 raw.githubusercontent.com

至此所有配置都配置完了
首先启动本地的项目 如我这次的项目启动在wyb-qa.guahao-test.com:8000
然后启动nginx

  1. sudo nginx

最后访问wyb-qa.guahao-test.com即可