#user nginx;
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# access_log /var/log/nginx/access.log main;
client_max_body_size 30m;
client_body_buffer_size 10m;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream wms-admin-web {
server 192.168.0.2:8082 max_fails=2 fail_timeout=10s;
server 192.168.0.3:8082 max_fails=2 fail_timeout=10s;
server 192.168.0.203:8082 max_fails=2 fail_timeout=10s;
#server 192.168.0.221:8082 max_fails=2 fail_timeout=10s;
}
upstream wms {
server 192.168.0.2:8083 max_fails=2 fail_timeout=10s;
#server 192.168.0.221:8083 max_fails=2 fail_timeout=10s;
}
upstream nacos_server {
server 192.168.0.2:8848 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.0.3:8848 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.0.203:8848 weight=1 max_fails=1 fail_timeout=10s;
}
server {
listen 80;
server_name localhost;
rewrite_log on;
error_log /var/log/nginx/error.log notice;
location / {
root /home/nginx/html;
#root /usr/share/nginx/html;
index index.html /home/nginx/index.html;
# proxy_pass http://wms-admin-web;
}
}
server {
listen 8090;
server_name localhost;
rewrite_log on;
error_log /var/log/nginx/error.log notice;
location /download/ {
root /home/nginx/;
}
location /img/ {
root /home/nginx/;
}
location / {
proxy_pass http://wms;
proxy_set_header Host $host:$server_port;
}
}
# nacos-server配置
server {
listen 8858;
server_name nacos.com; #nacos.com 映射配置
location / {
proxy_pass http://nacos_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
add_header Cache-Control no-cache;
}
}
include /etc/nginx/conf.d/*.conf;
}
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
#user nginx;
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
#redis代理测试
stream {
upstream redis {
#redis真实访问地址
server 192.168.0.2:6701 max_fails=3 fail_timeout=30s;
}
server {
#外网监听地址
listen 6379;
#代理连接超时时间
proxy_connect_timeout 5s;
#代理超时时间
proxy_timeout 30s;
#代理名称
proxy_pass redis;
}
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# access_log /var/log/nginx/access.log main;
client_max_body_size 30m;
client_body_buffer_size 10m;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream wms-admin-web {
server 192.168.0.2:8082 max_fails=2 fail_timeout=10s;
server 192.168.0.3:8082 max_fails=2 fail_timeout=10s;
server 192.168.0.203:8082 max_fails=2 fail_timeout=10s;
#server 192.168.0.221:8082 max_fails=2 fail_timeout=10s;
}
upstream wms {
server 192.168.0.2:8083 max_fails=2 fail_timeout=10s;
#server 192.168.0.221:8083 max_fails=2 fail_timeout=10s;
}
upstream nacos_server {
server 192.168.0.2:8848 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.0.3:8848 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.0.203:8848 weight=1 max_fails=1 fail_timeout=10s;
}
server {
listen 80;
server_name localhost;
rewrite_log on;
error_log /var/log/nginx/error.log notice;
location / {
root /home/nginx/html;
#root /usr/share/nginx/html;
index index.html /home/nginx/index.html;
# proxy_pass http://wms-admin-web;
}
}
server {
listen 8090;
server_name localhost;
rewrite_log on;
error_log /var/log/nginx/error.log notice;
location /download/ {
root /home/nginx/;
}
location /img/ {
root /home/nginx/;
}
location / {
proxy_pass http://wms;
proxy_set_header Host $host:$server_port;
}
}
# nacos-server配置
server {
listen 8858;
server_name nacos.com; #nacos.com 映射配置
location / {
proxy_pass http://nacos_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
add_header Cache-Control no-cache;
}
}
include /etc/nginx/conf.d/*.conf;
}
增加配置内容如下:
#redis代理测试
stream {
upstream redis {
#redis真实访问地址
server 192.168.0.2:6701 max_fails=3 fail_timeout=30s;
}
server {
#外网监听地址
listen 6379;
#代理连接超时时间
proxy_connect_timeout 5s;
#代理超时时间
proxy_timeout 30s;
#代理名称
proxy_pass redis;
}
}
1.nginx -V确保nginx安装了–with -stream如果没有,重新用yum install nginx -y安装
2. 安装 yum -y install epel-release
3. yum -y install nginx-all-modules.noarch
4.vi nginx.conf顶部加一行
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;