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
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了