Installation and configuration of Nginx for Linux services (CentOS)

Source: Internet
Author: User

Installing and configuring Nginx on Ubuntu/centos System

First, online installation:

Ubuntu:sudo Apt-get Install Nginx

Centos:sudo Yum Install Nginx

Second, the location after installation:

1. Service Address:/etc/init.d/nginx

2, configuration address:/etc/nginx/ :/etc/nginx/nginx.conf

    

3. Web default directory:/usr/share/nginx/http/ : usr/share/nginx/index.html

    

4, log directory:/var/log/nginx/ such as:/var/log/nginx/access.log

    

5. Main program file:/usr/sbin/nginx

Second, configure the website:

1, simple introduction to the function of the configuration file:

First you use the Cd/etc/nginx command to open to Nginx's main configuration directory and then call ll or LS to list the directories.

    

2, for example, I want to configure the following two sites:

(1) Access a website that is stored in the disk location via http://localhost:8080/:/var/www/html/.

(2) Access a website that is stored in the disk location via http://localhost:80/:/var/www/myweb/.

Implementation process:

(1) Open the CD to the/etc/nginx/sites-available directory and use the sudo vim./default to modify the default configuration file under this directory:

Modify the configuration information to the following:

server {        listen 8080 default_server;        Listen [::]:8080 default_server;        # SSL Configuration        #        # listen 443 SSL default_server;        # Listen [::]:443 SSL default_server;                root/var/www/html;        # Home Configuration        index index.html index.htm index.nginx-debian.html;        server_name _;        Location/{                try_files $uri $uri/=404;        }                } server {        listen;        Listen [::]:80;        server_name myweb;        Root/var/www/myweb;        Index index.html;        Location/{                try_files $uri $uri/=404;        }}

      

(2), Save the configuration file: Press Ecs to exit the edit status. shift+: When the command line appears, enter wq! to save. If the hint is that a read-only file cannot be saved, just use the sudo command to re-edit a previous step VI.

Third, start the service:

Input command: sudo systemctl restart Nginx.service

Or:sudo service nginx restart

Start.

      

Iv. Access Test results:

1, if you want to let the outside network access, need to shut down the firewall. Method: sudo iptables-f

2. Effect:

Test port 8080:

Test Port 80:

  

For more Nginx related tutorials, see the following :

CentOS 6.2 Combat Deployment nginx+mysql+php http://www.linuxidc.com/Linux/2013-09/90020.htm

Using Nginx to build a Web server http://www.linuxidc.com/Linux/2013-09/89768.htm

Build linux6.3+nginx1.2+php5+mysql5.5-based Web server whole process http://www.linuxidc.com/Linux/2013-09/89692.htm

Install Nginx-1.10.2 http://www.linuxidc.com/Linux/2016-10/136484.htm under Linux (RHEL7.0)

CentOS 6.3 under Nginx performance tuning http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 Under the configuration Nginx load ngx_pagespeed module http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 Installation Configuration nginx+pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx installation Configuration Use detailed note http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx log filtering using ngx_log_if does not log specific logs http://www.linuxidc.com/Linux/2014-07/104686.htm

detailed description of Nginx : please click here
Nginx : please click here.

This article permanently updates the link address : http://www.linuxidc.com/Linux/2016-11/137039.htm

Installation and configuration of Nginx for Linux services (CentOS)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.