nginx 的编译安装
1. 准备
下载地址:https://nginx.org/en/download.html
linux服务器环境
2. 安装
2.1 解压并进入源码目录
tar -zxvf nginx-1.24.0.tar.gz
cd nginx-1.24.0.tar.gz
2.2 安装 nginx编译时所需的依赖库
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.3 编译nginx,指定安装路径
./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream=dynamic
2.4 安装
make
make install
3. 启动
cd /data/nginx
sbin/nginx
4. 其他命令
测试: sbin/nginx -t
重载: sbin/nginx -reload
5. 代理配置
5.1 服务接口代理
新建配置文件夹,后续配置文件都存放在这里
mkdir conf.d
修改配置文件引入,使文件夹的文件生效
cd conf
vim nginx.conf
在 http {} 配置中的尾部,追加(一般为倒数第二行)
include /data/nginx/conf.d/*.conf;
新增简易代理配置
cd /data/nginx/conf.d
touch tomcat.conf
vim tomcat.conf
server { listen 9090; location / { proxy_pass http://localhost:8080; } }
5.2 数据库接口代理
nginx/modules
文件夹下需要有 ngx_stream_module.so
文件,如果不存在,需要重新编译,增加相关配置项
修改配置文件引入,使文件夹的文件生效
cd conf
vim nginx.conf
在顶部新增
#增加stream配置,开启stream模块 load_module /data/nginx/modules/ngx_stream_module.so; #stream模块和http模块是并列级别的,所以stream要写在http{}外边 stream { include /data/nginx/conf.d/*.stream; }
新增数据库接口代理配置
cd /data/nginx/conf.d
touch database.stream
vim database.stream
upstream mysql { server 127.0.0.1:3306; } server { listen 13306; proxy_pass mysql; proxy_timeout 28800s; }