How to install nginx in Linux

Home > Search > How-to
  by

Use yum to install nginx.

[root@server1 ~]# yum install epel-release
[root@server1 ~]# yum install nginx

 

Use systemctl to enable nginx, which ensure the service will automatically be active after a reboot.

[root@server1 ~]# systemctl enable nginx

 

Start nginx, and ensure nginx is active and running.

[root@server1 ~]# systemctl start nginx
[root@server1 ~]# systemctl status nginx

 

On a PC in the same subnet as the web server, navigate to http://x.x.x.x (replace x.x.x.x with the IP address of the web server). The default page should be displayed.

 

The /etc/nginx/nginx.conf file is configured to serve files in the /usr/share/nginx/html directory. The index.html file in the /usr/share/nginx/html directory produces the screen shot above.

[root@server1 ~]# cat /etc/nginx/nginx.conf
. . .
server {
  listen       80 default_server;
  listen       [::]:80 default_server;
  server_name  _;
  root         /usr/share/nginx/html;
. . .

 

In the /etc/nginx/nginx.conf file, add your domain name to the server_name line. In this example, the server_name is example.com. Also add index index.html to ensure that index.html files are served by default.

[root@server1 ~]# cat /etc/nginx/nginx.conf
. . .
server {
  listen       80 default_server;
  listen       [::]:80 default_server;
  server_name  www.example.com;
  root         /usr/share/nginx/html;
  index        index.html;
. . .

 

Restart nginx, and ensure nginx is active and running.

[root@server1 ~]# systemctl start nginx
[root@server1 ~]# systemctl status nginx

 

You can now access your site using your domain name.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments