爬行的蜗牛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: golang Linux PHP
查看: 1711|回复: 0

Nginx反向代理配置

[复制链接]

94

主题

36

回帖

849

积分

管理员

积分
849
发表于 2023-9-30 19:53:32 | 显示全部楼层 |阅读模式
  1. server
  2. {
  3.   #listen 80 reuseport;
  4.     listen 443 ssl http2 reuseport;
  5.     #listen 443 ssl http2;
  6.     server_name hub.0z.gs;
  7.     #root /web/nginx/stop;
  8.    
  9.     client_max_body_size 0;
  10.         gzip on;
  11.     gzip_min_length 1k;
  12.     gzip_buffers 4 16k;
  13.     gzip_http_version 1.1;
  14.     gzip_comp_level 9;
  15.     gzip_vary on;
  16.     gzip_proxied any; # test required
  17.     gzip_types
  18.         text/plain
  19.         text/css
  20.         text/js
  21.         text/xml
  22.         text/javascript
  23.         application/javascript
  24.         application/json
  25.         application/xml
  26.         application/rss+xml
  27.         image/svg+xml;
  28.    
  29.     if ($server_port !~ 443){
  30.        rewrite ^(/.*)$ https://$host$1 permanent;
  31.     }
  32.    
  33.     add_header Permissions-Policy interest-cohort=();
  34.    
  35.     ssl_stapling on;
  36.     ssl_stapling_verify on;
  37.     ssl_trusted_certificate /web/nginx/vhost/cert/github.0z.gs/fullchain.pem;
  38.     ssl_certificate    /web/nginx/vhost/cert/github.0z.gs/fullchain.pem;
  39.     ssl_certificate_key    /web/nginx/vhost/cert/github.0z.gs/privkey.pem;
  40.     ssl_protocols TLSv1.2 TLSv1.3;
  41.     ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  42.     ssl_prefer_server_ciphers on;
  43.     ssl_session_cache shared:SSL:10m;
  44.     ssl_session_timeout 60m;
  45.     ssl_session_tickets off;
  46.    
  47.     #add_header Strict-Transport-Security "max-age=31536000";
  48.     error_page 497  https://$host$request_uri;

  49.      # releases download
  50.     location ~ ^/[^/]+/[^/]+/releases/download/ {
  51.         return 301 https://download.0z.gs$request_uri;
  52.     }

  53.     # archive download
  54.     location ~ ^/[^/]+/[^/]+/archive/ {
  55.         return 301 https://archive.0z.gs$request_uri;
  56.     }
  57.    
  58.     location ~ ^/[^/]+/[^/]+/suites/[^/]+/artifacts/ {
  59.         return 301 https://download.0z.gs$request_uri;
  60.     }
  61.    
  62.     # Fuck Search Engine
  63.     location /robots.txt {
  64.         allow all;
  65.     }
  66.    
  67.     location / {
  68.    
  69.     proxy_set_header Access-Control-Allow-Origin *;
  70.     proxy_set_header Access-Control-Allow-Methods 'GET, POST, OPTIONS DELETE HEAD';
  71.     proxy_set_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Set-Cookie,Cookie,x-pjax-url';
  72.     add_header 'Access-Control-Allow-Credentials' 'true';

  73.     if ($request_method = 'OPTIONS') {
  74.         return 204;
  75.     }
  76.    
  77.         proxy_hide_header referrer-policy;
  78.         proxy_hide_header content-security-policy;
  79.         proxy_hide_header Strict-Transport-Security;
  80.         #proxy_hide_header set-cookie;
  81.         proxy_hide_header x-pjax-url;

  82.         proxy_set_header Host github.com;
  83.         proxy_set_header Accept-Encoding "";
  84.         proxy_set_header Referer https://github.com/;
  85.         proxy_set_header Origin https://github.com;
  86.         #proxy_set_header Connection "";

  87.         add_header x-pjax-url "https://hub.0z.gs$request_uri";

  88.         proxy_http_version 1.1;
  89.         proxy_connect_timeout 10s;
  90.         proxy_read_timeout 10s;
  91.         
  92.         proxy_socket_keepalive on;
  93.         
  94.         proxy_ssl_server_name on;

  95.         sub_filter ""https://raw.githubusercontent.com" ""https://raw.0z.gs";
  96.         sub_filter ""https://github.com" ""https://hub.0z.gs";
  97.         sub_filter ""https://github.githubassets.com" ""https://assets.0z.gs";
  98.         sub_filter ""https://github.githubassets.com" ""https://assets.0z.gs";
  99.         sub_filter "https://customer-stories-feed.github.com" "https://customer-stories-feed.0z.gs";
  100.         sub_filter_once off;
  101.         
  102.         proxy_cookie_domain github.com hub.0z.gs;

  103.         proxy_redirect https://github.com https://hub.0z.gs;
  104.         proxy_redirect https://raw.githubusercontent.com https://raw.0z.gs;
  105.         proxy_redirect https://github.githubassets.com https://assets.0z.gs;
  106.         proxy_redirect https://customer-stories-feed.github.com https://customer-stories-feed.0z.gs;
  107.         proxy_redirect https://codeload.github.com https://codeload.0z.gs;
  108.         
  109.         proxy_pass https://github;

  110.     }
  111.    

  112.     # Block search engine
  113.     # if ($http_user_agent ~* "qihoobot|Baiduspider|Bingbot|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
  114.     # {
  115.     #     return 403;
  116.     # }

  117.     # Anti Agent Bot DDoS
  118.     # If behind CDN, use folloing commented code
  119.     # if ($http_x_forwarded_for != $remote_addr) {
  120.     #     return 503;
  121.     # }
  122.    
  123.     if ($proxy_add_x_forwarded_for != $remote_addr) {
  124.         return 503;
  125.     }
  126.    
  127.    
  128.     access_log  /web/logs/github.0z.gs.log;
  129.     error_log  /www/logs/github.0z.gs.error.log;
  130. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表