1. 安装 brew
1
| /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
【报错】: Failed to connect to raw.githubusercontent.com port 443: Connection refused
换个命令重新安装:
1
| /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
|
参考: https://www.cnblogs.com/jiefangzhe/p/12929078.html
验证安装成功:
2. 安装 nginx
验证安装成功:
3. 修改 nginx配置
查看nginx配置文件路径: nginx -t
1. 定义需要转发的服务地址:
MacOS 12.1之后的配置存储位置为:/opt/homebrew/etc/nginx/nginx.conf
2. 配置请求转发:
4. 运行 nginx
1. 运行 nginx
2. 重新加载 nginx
3. 关闭 nginx
端口转发
用Nginx做端口转发(反向代理)
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| server{ listen 6605; server_name 47.94.144.238;
location / { proxy_pass http://192.168.1.3:80; } }
server{ listen 80; server_name localhost;
location ~ /{ root /www/wwwroot/zhangfan; index index.html; } }
server{ listen 801; server_name localhost;
location /{ proxy_pass http://localhost:6601; proxy_set_header HOST $host; } }
server{ listen 802; server_name localhost;
location /{ proxy_pass http://192.168.1.3:80; proxy_set_header HOST $host; } }
server{ listen 80; server_name tomcat.shaochenfeng.com; index index.php index.html index.htm;
location / { proxy_pass http://127.0.0.1:8080; # 转发规则 proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
|
配置参考
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
| server { listen 80; server_name testimages.zhuanzhi.ai; charset utf-8; location / { root /home/hujun/web/image; } }
server { listen 80; server_name medical.zhuanzhi.ai; charset utf-8;
location / { root /usr/share/nginx/zhitu/html; index index.html; proxy_set_header HOST $host; } location /zhitu-api { proxy_pass http://localhost:7075; proxy_set_header HOST $host;
|
配置
错误日志配置,在http
内
error_log /www/wwwlogs/zhangfan/nginx-error.log error;
Reference
- https://blog.csdn.net/weixin_40615155/article/details/108901854
- https://blog.csdn.net/weixin_45825077/article/details/107134300
- Nginx Linux详细安装部署教程