CentOS 7 Learning Note (ii) Nginx installation

Source: Internet
Author: User
Tags yum repolist

Description

1. The purpose of this learning record is to install Nginx on CentOS 7, including two installation methods, yum source installation and source code compilation and installation;

2, CentOS 7 beginners, some ideas with speculation, the lack of the text, also please criticize correct, will be taught in an open mind.

First part Yum source installation

  Yum source installation is relatively easy and does not have to deal with complex dependencies. For the first installation, I'll start with the Yum installation method. According to Nginx's wiki above the installation introduction.

The first step is to add the Yum source

To obtain the latest version of the Nginx,nginx installation instructions are recommended to download directly from the Nginx official website, you need to create a new source. Create a new file/etc/yum.repos.d/nginx.repo with the following content:

[Nginx] //Source name, will be recognized by Yum name=nginx Repo //File function description, just easy to understand the role of this file BaseURL=http://nginx.org/packages/centos/$releasever/$basearch///address, which is very important, where 7 (for 7.x) is a version,x86_64 is the basic CPU system
gpgcheck=0 //GPG Checksum, 0 for non-checksum, 1 for checksum
Enabled =1/enable, 0 means not enabled, 1 for enable

Among the BaseURL, the $releasever, $basearch is to obtain the version of the system, CPU basic system, these two variables used in the Yum file, the specific variable definition can find data.

After editing the file, execute the command as follows:

[email protected] etc]$Yum repolistloaded plugins: fastestmirrorloading mirror speeds fromCached Hostfile*Base: mirror.bit.edu.cn*extras:mirror.bit.edu.cn*updates:mirrors.btte.net Source Identity Source Name statusBase/7/x86_64 centos-7-Base8,465Extras/7/x86_64 centos-7-Extras104nginx/7/x86_64 nginx Repo 13//Description of new added source effectiveUpdates/7/x86_64 centos-7-Updates1,605repolist:10,187

When many sources are configured in the system and the same software is available, we will need to specify the source installation as follows:

[Email protected] etc]$sudo yum install nginx--enablerepo= nginx[sudo] password forTest:....================================================================================Package schema version source size================================================================================Installing: nginx x86_64 1:1.6.2-1.el7.ngx nginx 353 k transaction summary================================================================================installation1Total Package Downloads:353k installation Size:845KIs ThisOK [y/d/N]: y ...... Installing:1: nginx-1.6.2-1. el7.ngx.x86_641/1----------------------------------------------------------------------.....------------------------------------ ----------------------------------in the verification:1: nginx-1.6.2-1. el7.ngx.x86_641/1installed: nginx.x86_641:1.6.2-1. EL7.NGX finished! 

To view the Nginx default profile/etc/nginx/conf.d/default.conf, the contents are as follows:

server {    listen       ;                               //Monitor Port    server_name  //server name    #charset koi8-R;    #access_log  /var/log/nginx/log/host.access.log  main;     / {        root   /usr/share/nginx/html;                //Site root directory location        Index  index.html index.htm; //Site home default page name    }
......

To view Nginx service status, as follows:

[[Email protected]/sudo systemctl status nginx.service-nginx-High Performance Web server   loaded:load Ed (/usr/lib/systemd/system/nginx.service; disabled)   active:inactive (dead)      //Service not open 

To open the Nginx service, as follows:

sudo systemctl start Nginx.service
Check the status again, as follows

Nginx.service-nginx-high Performance Web Server
loaded:loaded (/usr/lib/systemd/system/nginx.service; disabled)
Active:active (running) since two 2015-01-27 22:53:46 CST; 44s ago//service turned on
......

When we use another PC to access the server, but found that cannot be opened because the firewall is turned on by default, prohibit access to port 80 (at this point, we think of the previous SSH, port 22, firewall default release). We need to add a firewall rule. At the same time, we can also shut down the firewall, testing whether the configuration is correct.

Note: I heard that before the firewall brand is Iptables,centos 7 default is firewall, the service name is FIREWALLD.

Add a firewall rule as follows:

sudo firewall-cmd--add-port=/tcp          //http protocol based on TCP transport protocol, release port 80

At this point we can use the command to view the FIREWALLD open port situation, before and after comparison as follows:

Before:
[email protected]/]$ sudo firewall-cmd--list- All Public(default) Interfaces:sources:services:dhcpv6-Client SSH//This is the default release of the Ports://Here is empty ... after:
[[Email protected]/]$ sudo firewall-cmd--list- All Public(default) Interfaces:sources:services:dhcpv6-Client SSH ports: 80/ TCP//This is the effect after we add the rule ....

When our browser enters the server address, see the Nginx Welcome page, prove the installation success! Here is the page that was successfully returned:

CentOS 7 Learning Note (ii) Nginx installation

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.