Advertisement
funcelot

jenkins nginx root config

Jan 28th, 2020
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.00 KB | None | 0 0
  1. upstream project {
  2.         server 127.0.0.1:8088;
  3. }
  4.  
  5. # Retain the default nginx handling of requests without a "Connection" header
  6. map $http_upgrade $connection_upgrade {
  7.     default          upgrade;
  8.     ''               close;
  9. }
  10.  
  11. # trust http_x_forwarded_proto headers correctly indicate ssl offloading
  12. map $http_x_forwarded_proto $pass_access_scheme {
  13.     default          $http_x_forwarded_proto;
  14.     ''               $scheme;
  15. }
  16.  
  17. map $http_x_forwarded_port $pass_server_port {
  18.     default           $http_x_forwarded_port;
  19.     ''                $server_port;
  20. }
  21.  
  22. map $http_x_forwarded_for $the_real_ip {
  23.     default          $http_x_forwarded_for;
  24.     ''               $remote_addr;
  25. }
  26.  
  27. # map port 8080 to 443 for header X-Forwarded-Port
  28. map $pass_server_port $pass_port {
  29.     8080             443;
  30.     default          $pass_server_port;
  31. }
  32.  
  33. # Map a response error watching the header Content-Type
  34. map $http_accept $httpAccept {
  35.     default          html;
  36.     application/json json;
  37.     application/xml  xml;
  38.     text/plain       text;
  39.     text/css         css;
  40.     text/javascript  js;
  41. }
  42.  
  43. map $httpAccept $httpReturnType {
  44.     default          html;
  45.     json             application/json;
  46.     xml              application/xml;
  47.     text             text/plain;
  48.     css              text/css;
  49.     js               text/javascript;
  50. }
  51.  
  52. # Obtain best http host
  53. map $http_host $this_host {
  54.     default          $http_host;
  55.     ''               $host;
  56. }
  57.  
  58. map $http_x_forwarded_host $best_http_host {
  59.     default          $http_x_forwarded_host;
  60.     ''               $this_host;
  61. }
  62.  
  63. server {
  64.         server_name dev.<site>.ru;
  65.  
  66.         client_max_body_size   100m;
  67.         proxy_read_timeout     3600s;
  68.         proxy_connect_timeout  3600s;
  69.  
  70.         gzip on;
  71.         gzip_disable "msie6";
  72.  
  73.         gzip_comp_level 2;
  74.         gzip_proxied any;
  75.         gzip_types
  76.                 text/plain
  77.                 text/css
  78.                 text/js
  79.                 text/javascript
  80.                 application/javascript
  81.                 application/x-javascript
  82.                 application/json
  83.                 application/xml
  84.                 image/svg+xml
  85.                 font/ttf
  86.                 application/vnd.ms-fontobject
  87.                 application/x-font-ttf
  88.                 application/font-woff
  89.                 application/font-woff2
  90.                 font/opentype;
  91.  
  92.         server_tokens off;
  93.  
  94.         location ^~ /jenkins {
  95.                 port_in_redirect off;
  96.  
  97.                 client_max_body_size                    "1m";
  98.                 proxy_set_header Host                   $host:$pass_server_port;
  99.  
  100.                 # Pass Real IP
  101.                 proxy_set_header X-Real-IP              $remote_addr;
  102.  
  103.                 # Allow websocket connections
  104.                 proxy_set_header                        Upgrade           $http_upgrade;
  105.                 proxy_set_header                        Connection        $connection_upgrade;
  106.  
  107.                 proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
  108.                 proxy_set_header X-Forwarded-Host       $host;
  109.                 proxy_set_header X-Forwarded-Port       $pass_port;
  110.                 proxy_set_header X-Forwarded-Proto      $pass_access_scheme;
  111.                 proxy_set_header X-Forwarded-Proto      $scheme;
  112.  
  113.                 # Custom headers
  114.  
  115.                 proxy_connect_timeout                   3600s;
  116.                 proxy_send_timeout                      3600s;
  117.                 proxy_read_timeout                      3600s;
  118.  
  119.                 proxy_redirect                          http://127.0.0.1:8080 https://dev.<site>.ru;
  120.                 proxy_buffering                         off;
  121.                 proxy_buffer_size                       "4k";
  122.  
  123.                 proxy_http_version                      1.1;
  124.  
  125.                 proxy_pass http://127.0.0.1:8080/jenkins;
  126.         }
  127.  
  128.         location / {
  129.                 client_max_body_size                    "1m";
  130.                 proxy_set_header Host                   $host:$pass_server_port;
  131.  
  132.                 # Pass Real IP
  133.                 proxy_set_header X-Real-IP              $remote_addr;
  134.  
  135.                 # Allow websocket connections
  136.                 proxy_set_header                        Upgrade           $http_upgrade;
  137.                 proxy_set_header                        Connection        $connection_upgrade;
  138.  
  139.                 proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
  140.                 proxy_set_header X-Forwarded-Host       $host;
  141.                 proxy_set_header X-Forwarded-Port       $pass_port;
  142.                 proxy_set_header X-Forwarded-Proto      $pass_access_scheme;
  143.                 proxy_set_header X-Forwarded-Proto      $scheme;
  144.  
  145.                 # Custom headers
  146.  
  147.                 proxy_connect_timeout                   3600s;
  148.                 proxy_send_timeout                      3600s;
  149.                 proxy_read_timeout                      3600s;
  150.  
  151.                 proxy_redirect                          http://127.0.0.1:8088 https://dev.<site>.ru;
  152.                 proxy_buffering                         off;
  153.                 proxy_buffer_size                       "4k";
  154.  
  155.                 proxy_http_version                      1.1;
  156.  
  157.                 proxy_redirect                       off;
  158.                 proxy_pass                           http://project;
  159.         }
  160.  
  161.     listen 443 ssl; # managed by Certbot
  162.     ssl_certificate /etc/letsencrypt/live/dev.<site>.ru/fullchain.pem; # managed by Certbot
  163.     ssl_certificate_key /etc/letsencrypt/live/dev.<site>.ru/privkey.pem; # managed by Certbot
  164. }
  165.  
  166. server {
  167.     if ($host = dev.<site>.ru) {
  168.         return 301 https://$host$request_uri;
  169.     } # managed by Certbot
  170.  
  171.     listen 80;
  172.     server_name dev.<site>.ru;
  173.  
  174.     return 404; # managed by Certbot
  175. }
  176.  
  177. server {
  178.     listen 80;
  179.  
  180.     server_name <real-ip>;
  181.  
  182.     #return 301 https://$host$request_uri;
  183.     return 301 https://dev.<site>.ru$request_uri;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement