解决方案 主要思路就是配置Nginx,将要访问的域名:80 转发至 启动的域名+启动的端口号,如wyb-qa.guahao-test.com 转发至 wyb-qa.guahao-test.com:8000
nginx的配置如下:
vim /usr/local/etc/nginx/nginx.conf
server {
listen 80;
server_name wyb-qa.guahao-test.com;
# proxy_set_header Cookie $http_cookie;
location / {
# proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Whatis-Scheme $scheme;
proxy_set_header Whatis-Host $http_host;
proxy_pass http://127.0.0.1:8000;
}
}
mac查看80端口是否被占用
lsof -i:80
接下来的问题就是如何在mac上安装nginx
安装nginx 需要先安装 brew
那么如何安装brew呢:
优先参考此文章
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
不行的话再参考以下步骤
可参考此文章:
具体步骤如下:
如果是已有brew 可先卸载:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"
卸载后再安装 ```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
brew安装成功后,那就开始安装nginx
```bash
brew install nginx
在安装nginx的过程中可能会遇到一些包下载不了的问题,需要配置host:
具体需要看日志看看哪些域名是404,比如我这次安装过程过程中就是github.com 和 raw.githubusercontent.com这两个域名下的包下载不了,那么就需要去该网站查看其对应的ip,然后再配置host
140.82.112.3 github.com
185.199.111.133 raw.githubusercontent.com
至此所有配置都配置完了
首先启动本地的项目 如我这次的项目启动在wyb-qa.guahao-test.com:8000
然后启动nginx
sudo nginx
最后访问wyb-qa.guahao-test.com即可