nginx安装
1.安装nginx https://www.runoob.com/linux/nginx-install-setup.html
2.如果需要代理mysql,redis之类的,编译安装nginx时需要--with-stream
举例 ./configure --with-stream --with-pcre=../pcre-8.35
3.比较熟悉情况下,推荐docker安装
nginx常用命令
1.nginx -version //查看版本
2.nginx //启动
3.nginx -s stop //停止
4.nginx -s reload //重新加载配置(热部署)
反向代理配置
1.配置应用层(普通开发的程序,都是基于http)
http {
include mime.types;
default_type application/octet-stream;
server {
listen 9001;
server_name localhost;
location / {
root html;
#配置被代理服务
proxy_pass http://host:port;
index index.html index.htm;
}
}
}
2.配置传输层(比如数据库或者一些中间价,为了追求性能,都是tcp)
stream{
#mysql反向代理
server {
listen 9000;
proxy_connect_timeout 10s;
proxy_timeout 525600m;
proxy_pass host:port;
}
}