Skip to content

Instantly share code, notes, and snippets.

@ecelis
Created October 3, 2019 21:19
Show Gist options
  • Select an option

  • Save ecelis/d3647d8ba953f3ecb18f936f39c693ea to your computer and use it in GitHub Desktop.

Select an option

Save ecelis/d3647d8ba953f3ecb18f936f39c693ea to your computer and use it in GitHub Desktop.

Revisions

  1. ecelis created this gist Oct 3, 2019.
    42 changes: 42 additions & 0 deletions nginx_api_spa.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
    }


    server {
    listen 80;
    server_name _;

    location /api/ {
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
    proxy_pass http://backend:8000;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location / {
    # Uncomment for production build
    #root /front;
    #index index.html index.htm;
    # Comment line below in production deployment
    proxy_pass http://spa:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }
    }