利用群晖自带的 Nginx 做反向代理

来自ling
跳转至: 导航搜索

https://www.jakehu.me/2021/synology-nginx/


扩展 /etc/nginx/conf.d目录

nginx -s reload

docker

 docker run --name nginx_oss --restart=always -p 6080:80  -v /volume3/oss_local:/usr/share/nginx/html:ro -d nginx

 docker run --name nginx --restart=always -p 666:80  \
-v /alidata/dockerdata/ling-cloud-ui2/dist:/usr/share/nginx/html:ro \
-v /volume3/oss_local:/usr/share/nginx/oss:ro \
-v /alidata/dockerdata/nginx/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx

nginx root与alias

qunhui

tee /etc/nginx/conf.d/dsm.ling.conf <<-'EOF'
         location ^~/oss {
           charset utf-8;
           alias /volume3/oss_local;
           autoindex on;
           autoindex_exact_size off;
           autoindex_localtime on;
           index chapter_local.html;
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
         location /xxl-job-admin{         
           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_pass http://127.0.0.1:3080;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
EOF

nginx

tee /alidata/dockerdata/nginx/nginx.conf <<-'EOF'
user  root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
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;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  cloudhome.ling2.cn;
 
         charset utf-8;
         location ^~/api/ver2.0/zy/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/zy/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/future/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/future/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/rule/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/rule/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/admin/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/admin/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/auth/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/auth/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/file/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/file/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/pay {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/pay/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         } 
         location ^~/api/ver2.0/es/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/es/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/api/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/api/(.*)$ /$1 break;
           proxy_pass http://192.168.30.2:5006;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/api/ver2.0/ {         
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   
           rewrite ^/api/ver2.0/(.*)$ /$1 break;
           proxy_pass http://127.0.0.1:9999;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           client_max_body_size    1000m;
         }
         location ^~/oss {
           alias /usr/share/nginx/oss;
           autoindex on;
           autoindex_exact_size off;
           autoindex_localtime on;
           index chapter_local.html;
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
         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;   
           alias /usr/share/nginx/html/;
           index  index.html index.htm;
           expires     -1;
         }
    }
}
EOF