centos7安装nginx

yum -y install openssl openssl-devel pcre pcre-devel gcc
./configure --prefix=/usr/local/nginx
make && make install

编辑nginx启动脚本
vim /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


chmod +x /lib/systemd/system/nginx.service
systemctl start nginx.service && systemctl enable nginx.service && systemctl status nginx.service

 

nginx添加tcp模块
./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module 
make 编译
不要make install,否则就是覆盖安装
/usr/local/nginx/sbin/nginx -V 查看nginx安装信息

添加tcp配置nginx.conf

 

stream {
# 添加socket转发的代理
upstream socket_proxy {
hash $remote_addr consistent;
# 转发的目的地址和端口
server 192.168.1.100:9000 weight=5 max_fails=3 fail_timeout=30s;
}

# 提供转发的服务,即访问localhost:9001,会跳转至代理socket_proxy指定的转发地址
server {
listen 9001;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass socket_proxy;
}
}

stream {

server {
listen xxxx; #访问localhost:xxxxx
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass 192.168.xx.xx:xxxx; #跳转到192.168.xx.xx:xxxxx
}
}

 

posted @ 2020-10-22 15:55  moxunjy  阅读(124)  评论(0)    收藏  举报