Nginx 安装配置

将文件传到Linux 服务器/opt 目录中
http://nginx.org/download/nginx-1.20.1.tar.gz

安装

#切换到 /opt目录下
cd /opt
# 安装依赖
yum -y install gcc zlib pcre-devel zlib-devel openssl openssl-devel
# 解压缩
tar -xzvf /opt/nginx-1.20.1.tar.gz 
cd /opt/nginx-1.20.1
#执行配置,并指定安装stream模块(四层代理使用),SSL HTTPS
./configure --with-stream --with-http_stub_status_module --with-http_ssl_module --with-stream_ssl_preread_module --with-stream_ssl_module
# 编译安装(默认安装在/usr/local/nginx)
make
make install

启动

#验证配置是否配置正确
/usr/local/nginx/sbin/nginx -t

#启动
/usr/local/nginx/sbin/nginx

开机自启动

vi /etc/rc.d/rc.local
#加入下列内容
/usr/local/nginx/sbin/nginx

配置

修改/usr/local/nginx/conf/nginx.conf

#stram 模块 和http模块是一同等级;做四层代理时需要添加上这个模块;
stream {                                           
    server {
        listen 17084;                          #四层代理转发 ;
        proxy_pass app_server;
    }
    upstream app_server{
        server 172.16.3.62:17084;
        server 172.16.3.62:17085;
    } 
} 

Nginx常用命令

测试配置文件:${Nginx}/sbin/nginx -t
启动命令:${Nginx}/sbin/nginx
停止命令:${Nginx}/sbin/nginx -s stop/quit
重启命令:${Nginx}/sbin/nginx -s reload
查看进程命令:ps -ef | grep nginx
平滑重启:kill -HUP [Nginx主进程号(即ps命令查到的PID)]
posted @ 2021-05-31 15:12  VipSoft  阅读(205)  评论(0编辑  收藏  举报