NGINX
table of contents
Introduction
NGINX is open-source web server software used for reverse proxy, load balancing, caching and https SSL termination.
brew install nginx
cd /usr/local/etc/nginx
cat nginx.conf
nginx # starts nginx
nginx.conf - configures the reverse proxy
Nginx Terms
- context - blocks
- directives - key value pair
events { # context
worker_connections 1024; # directive
}
serve static site
http {
# types {
# text/html html;
# text/css css;
# }
include mime.types;
server {
listen 8080;
root ./devops/nginx/mysite;
location / {
index index.html;
}
location /fruits {
root ./devops/nginx/mysite;
}
location /carbs {
alias ./devops/nginx/mysite;
}
location /vegetables {
root ./devops/nginx/mysite;
try_files /veggies.html /index.html =404;
}
location ~* /count/[0-9] {
root ./devops/nginx/mysite;
try_files /count.html /index.html =404;
}
# Redirect
location /crops {
return 307 /fruits;
}
# Rewrite
rewrite ^/number/(\w+)$ /count/$1 break;
}
}
events {
}
As Load Balancer
http {
upstream backendserver {
server 127.0.0.1:1111;
server 127.0.0.1:1112;
server 127.0.0.1:1113;
server 127.0.0.1:1114;
}
}
server {
listen 8080;
location / {
proxy_pass http://backendserver/;
}
}
