Step 1 – Install Nginx
Nginx packages are available under default repositories. Execute the following command to install latest Nginx available version on your system.
$ yum install nginx $ dnf install nginx#On Fedora 22+ systems
Step 2 – Nginx Basic Configuration
Do some initial setting before starting nginx. Edit Nginx main configuration file
$ vim /etc/nginx/nginx.conf
Update following values:
worker_processes 4; # Number of CPU available in system listen 80; # Port on which nginx will listen
Step 3 – Start Nginx Service
Use following commands to start Nginx web server and configure Nginx to autostart on system boot.
$ systemctl enable nginx.service $ systemctl start nginx.service
Now access your server on port 80 with your favorite browser, It will show default Nginx page.
Step 4 – Create VirtualHost in NGINX
After making initial configuration changes to NGINX, let’s start with configuring the first virtual host. Firstly create document root for your application.
$ sudo mkdir -p /var/www/example.com/httpdocs $ sudo chown -R nginx.nginx /var/www/example.com
Now create an index file with sample text
$ echo "Welcome to NGINX" > /var/www/example.com/httpdocs/index.html
Now create a virtual host configuration file. I just create a copy of default.conf file with name example.com.conf and edit file in the editor.
$ cp /etc/nginx/conf.d/virtual.conf /etc/nginx/conf.d/example.com.conf $ vim /etc/nginx/conf.d/example.com.conf
Make few changes in the configuration file like below and keep other settings as it is.
server { listen 80; server_name example.com; location / { root /var/www/example.com/httpdocs; index index.html index.htm; }
Finally, restart the NGINX service using the following command
$ sudo systemctl restart nginx.service
2 Comments
I think that you could do with some pics to drive the message home a little bit, but other than that, this is great blog. A great read. I will certainly be back.
wow, awesome blog article.Really looking forward to read more. Awesome.