Nginx代理jumpserver

IT
IT
IT
405
文章
1
评论
2021年1月29日13:14:30 评论 4,954 3415字阅读11分23秒

部署 Nginx 服务

  • 配置 Repo
[root@iZ2ze20kp0n3exw93yzsntZ ~]# vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
  • 安装 Nginx
[root@iZ2ze20kp0n3exw93yzsntZ ~]# yum install -y nginx
  • 配置 Nginx
[root@iZ2ze20kp0n3exw93yzsntZ ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confback
[root@iZ2ze20kp0n3exw93yzsntZ ~]# > /etc/nginx/nginx.conf
[root@iZ2ze20kp0n3exw93yzsntZ ~]# vi /etc/nginx/nginx.conf


user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}

stream {
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

access_log /var/log/nginx/tcp-access.log proxy;
open_log_file_cache off;

upstream kokossh {
server 192.168.1.245:2222;
least_conn;
}

server {
listen 2222;
proxy_pass kokossh;
proxy_protocol on;
proxy_connect_timeout 1s;
}
}

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;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

[root@iZ2ze20kp0n3exw93yzsntZ ~]# echo > /etc/nginx/conf.d/default.conf
[root@iZ2ze20kp0n3exw93yzsntZ ~]# vi /etc/nginx/conf.d/jumpserver.conf

upstream jumpserver {
server 192.168.1.245:8080;
ip_hash;
}

upstream core {
server 192.168.1.245:8080 max_fails=1 fail_timeout=1s;
}

server {
listen 80;
server_name jump.centoscn.vip; # 自行修改成你的域名
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name jump.centoscn.vip; # 自行修改成你的域名
ssl_certificate /etc/nginx/scs1611589437436/Nginx/server.crt; # 自行设置证书
ssl_certificate_key /etc/nginx/scs1611589437436/Nginx/server.key; # 自行设置证书
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

client_max_body_size 4096m; # 录像上传大小限制

location /api/v1/terminal/ {
proxy_pass http://core/api/v1/terminal/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_next_upstream_tries 3;
}

location /media/ {
proxy_pass http://core/media/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_next_upstream_tries 3;
}

location / {
proxy_pass http://jumpserver;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}
}
  • 启动
[root@iZ2ze5eakhpbms7qco8gcvZ Nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@iZ2ze5eakhpbms7qco8gcvZ Nginx]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@iZ2ze5eakhpbms7qco8gcvZ Nginx]# systemctl start nginx

访问

  • http://jump.centoscn.vip

Nginx代理jumpserver

Nginx代理jumpserver

继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2021年1月29日13:14:30
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Nginx正向反向代理区别及原理解析 nginx

Nginx正向反向代理区别及原理解析

正向代理和反向代理的区别 正向代理代理客户端,反向代理代理服务器。 1.1正向代理 正向代理服务器位于客户端和服务器之间,为了从服务器获取数据,客户端要向代理服务器发送一个请求,并指定目标服务器,代理...
Nginx正向代理配置 nginx

Nginx正向代理配置

通过把Nginx设置为正向代理,我们就可以在局域网中用运行着Nginx的主机作为正向代理服务器了。那什么是正向代理和反向代理呢?正向代理和反向代理-百度百科 正向代理:如果把局域网外的Internet...

您必须才能发表评论!