brew install nginx
brew info nginx
nginx: stable 1.23.1 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.23.1 (26 files, 2.2MB) *
Poured from bottle on 2022-08-22 at 15:35:18
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 ✔, pcre2 ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www
The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /opt/homebrew/etc/nginx/servers/.
Docroot is: /opt/homebrew/var/www
conf:/opt/homebrew/etc/nginx/nginx.conf
load:/opt/homebrew/etc/nginx/servers/
启动:
nginx
停止
nginx -s stop
localhost:8080(我是修改成了80端口)
nginx 启动
nginx -s reload 重新加载配置文件
访问localhost:82 会去访问 IP地址:端口
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://IP地址:端口; #反向代理配置,将请求转发到指定服务
}
}
访问localhost:82 会去访问 IP地址1:端口1 和 IP地址2:端口2
targetserver 是自定义的
#upstream指令可以定义一组服务器
upstream targetserver{
server IP地址1:端口1 weight=10; # 权重的分配的请求概率大
server IP地址2:端口2 weight=5;
}
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://targetserver;
}
}