NGINX is a robust web server that can be configured to server static, dynamic or custom contents and also can be used as reverse proxy or loadbalancer.
Install on RHEL with command –
yum install nginx
start service –
systemctl start nginx
Check service status –
ps -ef | grep nginx
root 3295701 1 0 12:37 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 3295702 3295701 0 12:37 ? 00:00:00 nginx: worker process
nginx 3295703 3295701 0 12:37 ? 00:00:00 nginx: worker process
root 3295718 3250048 0 12:37 pts/1 00:00:00 grep –color=auto nginx
NGINX has –
main context
server context
http context
create a virtual host to server the static website
I personally prefer to clean the default file and add my our code –
events {}
http{
server {
listen 8880;
server_name vm01.cloudshiksha365.com;
root /u01/cs365/html;
}
}
Post changes, next is to do the stop and start of nginx demon –
[root@cs365-vm01 ~]# nginx -t
[root@cs365-vm01 ~]# systemctl stop nginx
[root@cs365-vm01 ~]# systemctl start nginx
Make sure following permission and security checks –
chown nginx:group /u01/cs365/html
chcon -R -t httpd_sys_content_t /u01/cs365/html
Refer to error logs if your webpage is not accessible –
tail -f /var/log/nginx/error.log
Below with Mime Type Manually defined –
events {}
http{
types {
text/html html;
text/css css;
}
server {
listen 80;
server_name vm01.cloudshiksha365.com;
root /u01/cs365/html;
}
}
SSH Tunnel to your local desktop from server if firewall is a problem –
ssh -m hmac-sha2-512 -L 8181:localhost:80 [email protected]
NGINX Location blocks with prefix match examples –
events {}
http{
include mime.types;
server {
listen 80;
server_name cs365vm01.cloudshiksha365.com;
root /u01/forms/html;
#Prefix match
location /app1 {
return 200 “app 1 sample call”
}
#exact match
location = /app2 {
return 200 “app 1 sample call”
}
#regx based match use PCRE lib, its case sensitive, remember this
location ~ /app3[0-9] {
return 200 “app 3 sample call with REGX Match “
}
#regx based match use PCRE lib, its case insensitive, remember this with * use here
location *~ /app3[0-9] {
return 200 “app 3 sample call with REGX Match “
}
#Preferential prefix match use PCRE lib, its case insensitive, remember this with * use here
location ^~ /app3[0-9] {
return 200 “app 3 sample call with REGX Match “
}
}
}
NGINX as a Reverse Proxy –
events {}
http{
include mime.types;
server {
listen 80;
server_name cs365vm01.cloudshiksha365.com;
root /u01/forms/html;
location /myapp {
proxy_pass 'http://localhost:9090';
}
}
Below is the example config that I am using on one of my LIVE servers with SSL/TLS –
server { listen 4443;
server_name dev.cs365.com;
ssl_certificate /kst-ngx_certs/devcs365.crt; ssl_certificate_key /kst-ngx_certs/devcs365.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on;
access_log /var/log/nginx/cs365.access.log;
root /kst-ngx_htdocs;
