怎么使用Nginx反向代理Rancher

  1. 环境查看
    系统环境
# cat /etc/redhat-release 
Rocky Linux release 9.4 (Blue Onyx)
# uname -a
#1 SMP PREEMPT_DYNAMIC Thu Sep 12 18:24:53 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

软件环境

# nginx -version
nginx version: nginx/1.26.2
  1. Nginx配置文件
    已经搭建好Rancher如果在内网直接使用ip访问会强制加https,使用Nginx反向代理80端口
    配置文件如下
    主配置文件
]# cat /usr/local/nginx/conf/nginx.conf
user  nginx;
worker_processes  1;
worker_rlimit_nofile 65535;
events {
    worker_connections  1024;
}


http {
    include       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"';
    proxy_ignore_client_abort on;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 500000M;
    client_body_buffer_size 500000M;
    include ./conf.d/*.conf;
}

rancher配置文件

# cat /usr/local/nginx/conf/conf.d/rancher.conf 
server {
        listen       80;
        server_name  rancher-ss.xxx.com;
        access_log  logs/host.access.log  main;
        location /
        {
            rewrite ^(.*) https://$server_name$1 permanent;
        }
        error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}
    }
server {
        listen       443 ssl;
        server_name  rancher-ss.cloud.com;
        ssl_certificate      /usr/local/nginx/conf/ssl/xxx.com.pem;
        ssl_certificate_key  /usr/local/nginx/conf/ssl/xxx.com.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        location /
        {   
             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 X-Forwarded-Proto $scheme;
             proxy_pass http://rancher-ss.xxx.com;
        }
    }

反向代理文件
反向的是rancher服务器的80端口

# cat /usr/local/nginx/conf/conf.d/upstream.conf 
upstream rancher-ss.xxx.com{
    server 192.168.3.61:80;
}

关键配置如下
image

posted @   minseo  阅读(110)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2019-09-19 Docker入门之docker-compose
点击右上角即可分享
微信分享提示