Created
May 10, 2014 20:18
-
-
Save calebwoods/5e88b5e323d55ad71195 to your computer and use it in GitHub Desktop.
Sample Nginx config for deployment of Angular.js app
This file contains 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
server { listen 80; | |
server_name example.com; | |
access_log /var/log/example.com/nginx.access.log; | |
error_log /var/log/example.com/nginx.error.log; | |
root /var/www/apps/example.com/public; | |
charset utf-8; | |
location / { | |
rewrite ^ https://$host$request_uri? permanent; | |
} | |
} | |
server { | |
listen 443 ssl; | |
server_name example.com; | |
access_log /var/log/example.com/nginx.access.log; | |
error_log /var/log/example.com/nginx.error.log; | |
ssl_certificate /etc/nginx/ssl/example.com.pem; | |
ssl_certificate_key /etc/nginx/ssl/example.com.key; | |
keepalive_timeout 5; | |
root /var/www/apps/example.com/dist; | |
charset utf-8; | |
location ~ ^/(scripts.*js|styles|images) { | |
gzip_static on; | |
expires 1y; | |
add_header Cache-Control public; | |
add_header ETag ""; | |
break; | |
} | |
location /api1 { | |
rewrite ^/api1/(.*) /$1 break; | |
proxy_redirect off; | |
proxy_pass https://api1.example.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto https; | |
proxy_set_header Authorization $http_authorization; | |
} | |
location /api2 { | |
rewrite ^/api2/(.*) /$1 break; | |
proxy_redirect off; | |
proxy_pass https://api2.example.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto https; | |
proxy_set_header Authorization $http_authorization; | |
} | |
location / { | |
try_files $uri /index.html; | |
} | |
} |
hmm, hit a problem. now it doesn't work. I wanted to be able to handle both uri and query string in the angular app, and also have an api in the subdirectory.
doesn't work though:
location ~ ^/(api) {
rewrite ^/api/(.*) /$request_uri break;
index index.php;
try_files $request_uri $request_uri/ /index.php?$query_string;
}
location / {
include /etc/nginx/mime.types;
try_files $uri /index.html?$query_string;
}
plase explain me im newbie on this.
- are client and server must be on different domain like (client: example.com and server: srv.example.com)
- i just 1 ssl for 1 domain and not suport for subdomain. if qst no.1 true so i have got 2 ssl to make this work ?
- our system use nodejs on backend and angularjs on fronted and run under nginx. must i set ssl on client and server ( i have already set ssl on server side)
thanks for your answer
I want to load balance an Multiple Mean App through NGINX. How can I do that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1, i would like to know the same.