Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.75 KB | None | 0 0
  1. # normally you leave this at the default of 1024
  2. events {
  3.     worker_connections 1024;
  4. }
  5.  
  6. http {
  7.     client_max_body_size 512M;
  8.  
  9.     upstream django {
  10.         server web:8000;
  11.     }
  12.  
  13.     sendfile on;
  14.     send_timeout 300s;
  15.  
  16.     server {
  17.         client_max_body_size 512M;
  18.  
  19.         listen 80 default_server;
  20.         server_name my.site.ru;
  21.  
  22.         # ------------------------------------------------------------  STATIC FILES  ---
  23.         location /static {
  24.             location /static/admin          { alias /app/static-files/admin; }
  25.             location /static/rest_framework { alias /app/static-files/rest_framework; }
  26.             location /static/debug_toolbar  { alias /app/static-files/debug_toolbar; }
  27.  
  28.             location /static/fonts          { alias /webapp/build/static/fonts; }
  29.             location /static/icons          { alias /webapp/build/static/icons; }
  30.             location /static/images         { alias /webapp/build/static/images; }
  31.             location /static/img            { alias /webapp/build/static/img; }
  32.  
  33.             # new path from webpack
  34.             location /static/scripts        { alias /webapp/build/static/scripts; }
  35.             location /static/styles         { alias /webapp/build/static/styles; }
  36.  
  37.             # http://stackoverflow.com/q/19213510/1346257
  38.             include /etc/nginx/mime.types;
  39.             autoindex off;
  40.         }
  41.  
  42.         location /assets {
  43.             alias /webapp/build/assets;
  44.             include /etc/nginx/mime.types;
  45.             autoindex off;
  46.         }
  47.  
  48.         # -----------------------------------------------------------  COMMON CONFIG  ---
  49.         location = /robots.txt { return 200 "User-agent: *\nAllow: /"; }
  50.         location = /favicon.ico {
  51.             add_header 'Content-Type' image/vnd.microsoft.icon;
  52.             alias /webapp/build/favicon.ico;
  53.             access_log off;
  54.             log_not_found off;
  55.         }
  56.  
  57.         #Prevent serving of sysfiles / vim backup files
  58.         location ~ /\. { access_log off; log_not_found off; deny all; }
  59.         location ~ ~$  { access_log off; log_not_found off; deny all; }
  60.  
  61.  
  62.         # --------------------------------------------------------------  USER FILES  ---
  63.         location /file/uploads/public/ {
  64.             add_header 'Access-Control-Allow-Origin' * always;
  65.             alias /app/uploads/public/;
  66.             include /etc/nginx/mime.types;
  67.             autoindex off;
  68.         }
  69.  
  70.         # -------------------------------------------------------------------  ICONS  ---
  71.         location /file/uploads/icon/ {
  72.             add_header 'Access-Control-Allow-Origin' * always;
  73.             alias /app/uploads/icon/;
  74.             include /etc/nginx/mime.types;
  75.             autoindex off;
  76.         }
  77.  
  78.  
  79.         # ------------------------------------------------------------  SYSTEM FILES  ---
  80.         location /file/uploads/sys/ {
  81.             add_header 'Access-Control-Allow-Origin' * always;
  82.             alias /app/uploads/sys/;
  83.             include /etc/nginx/mime.types;
  84.             autoindex off;
  85.         }
  86.  
  87.         # ------------------------------------------------  REDIRECT TO  /index.html  ---
  88.         # redirect all requests to /index.html
  89.         location / {
  90.             client_max_body_size 512M;
  91.  
  92.             rewrite ^ /index.html;
  93.         }
  94.  
  95.         location = /index.html {
  96.             alias /webapp/build/index.html;
  97.         }
  98.  
  99.         location = /manifest.json {
  100.             alias /webapp/build/manifest.json;
  101.         }
  102.  
  103.         # ---------------------------------  MAIN ENTRYPOINT: /api /admin /rest-auth  ---
  104.         location /api/ {
  105.             client_max_body_size 512M;
  106.  
  107.             add_header 'Access-Control-Allow-Origin' * always;
  108.             add_header 'Access-Control-Allow-Credentials' 'true' always;
  109.             add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,Cache-Control,X-Mx-ReqToken,Keep-Alive,If-Modified-Since,X-CSRF-Token,x-csrftoken,X-CSRFToken,X-$
  110.            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH' always;
  111.  
  112.            if ($request_method = 'OPTIONS') {
  113.                add_header 'Access-Control-Allow-Origin' * always;
  114.                add_header 'Access-Control-Allow-Credentials' 'true' always;
  115.                add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,Cache-Control,X-Mx-ReqToken,Keep-Alive,If-Modified-Since,X-CSRF-Token,x-csrftoken,X-CSRFToke$
  116.                 add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH' always;
  117.  
  118.                 add_header 'Content-Length' 0 always;
  119.                 add_header 'Content-Type' application/json always;
  120.                 expires 1d;
  121.                 access_log off;
  122.                 return 204;
  123.             }
  124.  
  125.             uwsgi_pass      django;
  126.             include         uwsgi_params;
  127.         }
  128.  
  129.         location /rest-auth/ {
  130.             add_header 'Access-Control-Allow-Origin' * always;
  131.             add_header 'Access-Control-Allow-Credentials' 'true' always;
  132.             add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,Cache-Control,X-Mx-ReqToken,Keep-Alive,If-Modified-Since,X-CSRF-Token,x-csrftoken,X-CSRFToken,X-$
  133.            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH' always;
  134.  
  135.            uwsgi_pass      django;
  136.            include         uwsgi_params;
  137.        }
  138.        
  139.        location /admin/ {
  140.            uwsgi_pass      django;
  141.            include         uwsgi_params;
  142.        }
  143.  
  144.        location /__debug__/ {
  145.            uwsgi_pass      django;
  146.            include         uwsgi_params;
  147.        }
  148.  
  149.        error_page  405     =200 ;
  150.    }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement