Created
November 13, 2018 04:11
-
-
Save shrekuu/7cfc2f9d11b8927142dc9fbfaa62150d to your computer and use it in GitHub Desktop.
nginx config for multiple angular projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config for 3 vhost; 2 angular projects, 1 backend api project. | |
| # angular project1 | |
| # replace project1 with your own | |
| server { | |
| listen 80; | |
| server_name project1.test; | |
| access_log logs/project1.test-access.log; | |
| error_log logs/project1.test-error.log; | |
| root /var/www/project1/dist; | |
| index index.html index.htm; | |
| location /sockjs-node/ { | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| rewrite ^/(.*)$ /$1 break; | |
| proxy_set_header Host localhost; | |
| proxy_pass http://localhost:4201/; | |
| } | |
| location / { | |
| proxy_pass http://localhost:4201; | |
| } | |
| } | |
| # angular project2 | |
| # replace project2 with your own | |
| server { | |
| listen 80; | |
| server_name project2.test; | |
| access_log logs/project2.test-access.log; | |
| error_log logs/project2.test-error.log; | |
| root /var/www/project2/dist; | |
| index index.html index.htm; | |
| location /sockjs-node/ { | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| rewrite ^/(.*)$ /$1 break; | |
| proxy_set_header Host localhost; | |
| proxy_pass http://localhost:4200/; | |
| } | |
| location / { | |
| proxy_pass http://localhost:4200; | |
| } | |
| } | |
| # backend api project3 | |
| server { | |
| listen 80; | |
| server_name project3.test; | |
| root /var/www/project2/public; | |
| index index.php index.html index.htm; | |
| access_log logs/project3.test-access.log; | |
| error_log logs/project3.test-error.log; | |
| # CORS config, local development, bypass all requests | |
| add_header Access-Control-Allow-Origin $http_origin; | |
| add_header 'Access-Control-Allow-Headers' 'content-type, origin, authorization, accept, client-security-token'; | |
| add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE'; | |
| add_header 'Access-Control-Allow-Credentials' 'true'; | |
| location / { | |
| try_files $uri $uri/ /index.php?$query_string; | |
| } | |
| location ~* \.php$ { | |
| try_files $uri = 404; | |
| fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
| fastcgi_pass 127.0.0.1:9000; | |
| fastcgi_index index.php; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
| include fastcgi_params; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment