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 @   moxunjy  阅读(110)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示