NGINX installation
To install NGINX follow this step by step instructions below:
- Add EPEL Repository. To add the CentOS 7 EPEL repository, open terminal and use the following command:
sudo yum install epel-release
- Install Nginx:
sudo yum install nginx
- If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
- To create configuration file run:
sudo vim /etc/nginx/conf.d/domain.conf
- And copy below configuation into it:
YOUR_DOMAIN_NAME - replace with your domain name
CERTIFICATE_PATH - replace with your certificate location
PRIVATE_KEY_PATH - replace with your private key location
server {
listen 80;
server_name YOUR_DOMAIN_NAME;
return 301 https://$host$request_uri;
}
server {
server_name YOUR_DOMAIN_NAME_HERE;
listen 443 ssl;
client_max_body_size 200M;
ssl on;
ssl_certificate CERTIFICATE_PATH;
ssl_certificate_key PRIVATE_KEY_PATH;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
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 $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|woff2|ttf|woff|eot|svg)$ {
proxy_pass http://localhost:8080;
access_log off;
expires 1y;
}
}
- Start Nginx service:
sudo systemctl start nginx
- You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser:
https://server_domain_name/
- Enable Nginx service to start when your system boots:
sudo systemctl enable nginx