Nginx
Docs
Install Docs
(1) Install for CentOS/RHEL
- it works with brotli source code compilation..etc
Package from the Official NGINX Repository
Create the file nginx.repo in /etc/yum.repos.d
sudo vim /etc/yum.repos.d/nginx.repoAdd the following lines to nginx.repo:
[nginx]name=nginx repobaseurl=https://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1Note : OS is either rhel or centos, 'OSRELEASE' is the release number (6, 6.x, 7, 7.x and so on)
Update the repository:
sudo yum updateInstall the NGINX Open Source package
sudo yum install nginxIf you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:
Note : Make SELINUX settings to disabled/permissive to allow nginix to serve new location static content. Commands (MD)
(1) Install for Ubuntu
Create a new file '/etc/apt/sources.list.d/nginx.list'
Syntax content
- Add below content if ubuntu 20.04
- Update repo & install nginx
If we get error 'Err:5 https://nginx.org/packages/ubuntu focal InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62'execute following
- Re try nginx installation
- allow http & https port
(2) Start & Verify
Start NGINX Open Source:
sudo nginxIf port 80 in use error, kill the process
Verify that NGINX Open Source is up and running:
curl -I 127.0.0.1OR open browser & type ipaddress
(3) Application on system reboot
Enable Nginx to start when your system boots
Commands
Start Nginx
Stop Nginx
Restart Nginx
Reload Nginx configurations.
To verify config file
Serving static content
- Open file '/etc/nginx/nginx.conf'
If you read "include /etc/nginx/conf.d/*.conf;" line, we can create new configuration file in specified folder
Create file with domain/ip address name (eg: 10...*.conf) in '/etc/nginx/conf.d' folder
server {# --- listening to port 80listen 80 backlog=4096;# --- specify private & public ip, domain nameserver_name 192.*.*.* 10.*.*.* www.domain.com;# --- specify root folder (all static applications can reside in it)root /some/root/location/to/browse;location / {# --- let landing index.html call -> default-pages/index.htmlindex index.html readme.html master.html;}# --- Say to deny some file type requestslocation ~ \.(md|sh) {deny all;}# ---- custom error pages --------------------------------error_page 404 /404.html;location = /404.html {root /some/root/location/to/browse/default-pages;}error_page 403 /403.html;location = /403.html {root /some/root/location/to/browse/default-pages;}
location /someProject {
}
location /somePath {
}
netstat ipaddr
sudo sysctl -w net.core.somaxconn=4096
net.core.somaxconn = 4096
server { listen 80 backlog=4096;
}
- Clone ngx_brotli from Github https://github.com/google/ngx_brotli
Check your Nginx version with command:
- Now you need to download Nginx source, depend on your Nginx version.
- In this example is Nginx 1.16.1, compile module and compiled Nginx Brotli located in objs.
Enable GZIP & Brotli Compression
Edit nginx configuration file – /etc/nginx/nginx.conf and add these lines near top
Now global nginx.conf (under http section) or specific.conf - add following
- by default for https connections, brotli 'Accept-Encoding' is present in request header
Note : Restart Nginx
Set up SSL on Nginx
- First copy your DigiCertCA.crt (intermediate certificate), domain.crt (primary certificate) and domain.key to server
- Make those files readable by root only to increase security.
- Since .pem file was not provided, concatenate the primary and intermediate certificates
- Edit the Nginx virtual hosts file
- 443 is https default port (Same must be opened in local & main firewall)
- check remotely by 'telnet publicIp port'
- Verify nginx config by -t command
- Restart the Nginx