Table of Contents

How to install Nginx on centos

sudo yum install epel-release
sudo yum install nginx

Let us check the status of nginx

sudo service nginx status
Active: inactive (dead)

It is dead. We need to start it.

sudo service nginx start
sudo service nginx status
 Active: active (running) since Sun 2019-08-18 00:11:52 EDT; 8s ago

Now it is running.

Lets create a conf file /etc/nginx/conf.d/dashboard.conf

vi the file and add following content...

server {
        server_name  hostname;
        listen 80;

        error_log  /var/log/nginx/api_nginx_error.log  warn;

        location /static/ {
            alias /home/sites/dir1/static/;
            expires 365d;
        }
        location / {
                proxy_pass http://127.0.0.1:88;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        }
}

The above config starts the nginx listen on port 80. If the request comes from domain hostname nginx will forward that request to service running at

http://127.0.0.1:88. Static files will be served from the /home/sites/dir1/static/ directory.


Related Posts