官网:https://nginx.org/
wget -P /usr/src/ https://nginx.org/download/nginx-1.21.0.tar.gz
#指定存放目录来下载
yum -y install gcc-c++
yum -y install openssl
yum -y install pcre-devel
yum -y install zlib-devel
#最小化安装的话,需要提前安装依赖包
cd /usr/local/nginx-1.21.0/
./configure && make && make install
#直接预配置 && 编译 && 安装,有需求可以在预配置这环节添加
nginx的配置文件:
user nginx; #指定用户 worker_processes 1; #优化nginx进程个数,不超过cpu的数量 events { worker_connections 1024; #一个worker进程的并发 use epoll; #选择用epoll模型 } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server_tokens off; #隐藏版本号 server { listen 80; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://127.0.0.1:3000; } location /metrics/ { root html; index index.html index.htm; proxy_pass http://127.0.0.1:9100/metrics; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
还有相关gzip、expires、日志等优化,静等下次更新
一句话:正向代理客户端,反向代理服务器
在location段里添加:proxy_pass http://127.0.0.1:3000;