- 环境查看
系统环境
# 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
- 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.xiaoxingcloud.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;
}
关键配置如下