Nginx设置反向代理

源码编译安装Nginx
参考:
https://i.cnblogs.com/posts/edit-done;postId=9010150;isPublished=false

  1. 设置include
    因为反向代理主机较多设置include可以模块化各个主机
    nginx配置文件
# sed '/#/d' /usr/local/nginx/conf/nginx.conf|sed '/^$/d'
worker_processes  1;
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"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 4096M;
    include  ./conf.d/*.conf;
}
  1. 设置反向代理
    在conf目录创建目录conf.d用于放置多域名配置文件
    虚拟主机配置文件
# sed '/#/d' conf.d/harbor.conf |sed '/^$/d'
server {
        listen       80;
        server_name  harbor.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  localhost;
        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_pass http://harbor.xxx.com;
        }
    }

负载均衡配置文件

# cat conf.d/upstream.conf 
upstream harbor.xxx.com{
    server 172.16.5.102:80;
}

解释
image
image

posted @ 2024-06-03 16:30  minseo  阅读(16)  评论(0编辑  收藏  举报