"Nginx" Linux installation Nginx

Source: Internet
Author: User
Tags install openssl nginx reverse proxy

    • Installation Dependencies ()
      • · Yum Install GCC
      • · Yum Install Pcre-devel
      • · Yum Install zlib Zlib-devel
      • · Yum Install OpenSSL Openssl-devel
      • · One-click installation of the above four dependencies
      • · Yum-y install gcc zlib zlib-devel pcre-devel OpenSSL openssl-devel
    • Download Nginx of the Tar Package
      • · Create a folder
      • · Cd/usr/local
      • · mkdir Nginx
      • · CD Nginx
      • · Download the TAR Package
      • . wget http://nginx.org/download/nginx-1.13.7.tar.gz
      • .//Unzip the TAR package
      • TAR-ZXVF nginx-1.13.7.tar.gz

  • Install nginx ( if Configure report xx not found Add with-xx= path )
    • //Enter Nginx directory
    • cd/usr/local/nginx
    • • Execute configuration Command Note:--with-http_ssl_module turns on the SSL module and supports HTTPS requests
    • ./configure--prefix=/usr/local/nginx--sbin-path=/ Usr/local/nginx/sbin/nginx--conf-path=/usr/local/nginx/conf/nginx.conf--with-http_stub_status_module-- With-http_ssl_module--with-openssl=/home/admin/openssl/openssl-1.1.0e
    • //execute make command
    • make
    • Execute the Make install command
    • make install
  • Nginx common commands
    • //Test profile
    • install path/nginx/sbin/nginx-t
    • //start command
    • /nginx/sbin/nginx under Installation path
    • //Stop command
    • installation path under/nginx/sbin/nginx-s stop  or: N Ginx-s quit
    • //restart command
    • installation path/nginx/sbin/nginx-s reload
    • View process Commands
    • Ps-ef | grep nginx
    • Smooth restart
    • Kill-hup Nginx Main process number
    • Configuring firewalls
      • Open the firewall file
      • sudo vim/etc/sysconfig/iptables
      • New Line Open 80 port
      • -A input-p tcp-m state--state new-m TCP--dport 80-j ACCEPT
      • Save fallback
      • Restarting the firewall
      • sudo service iptables restart
    • Nginx virtual domain name configuration and test verification
      • · Edit nginx.conf
      • · sudo vim/usr/local/nginx/conf/nginx.conf
      • · Increase row
      • · Include vhost/*.conf
        Save exit
      • · Create a new Vhost folder in the/usr/local/nginx/conf directory
      • · mkdir Vhost
        Create a configuration for each domain name
        sudo vim jimisun.com.conf
        Configure port forwarding or access to the file system in a node that adds a response
    • Nginx Start
      • · Enter the Nginx installation directory
      • · CD Sbin
      • · sudo./nginx
      • Test access

HTTP://IP Address

Note: Nginx error when installing: Make : * * * No rule to do target ' build ', needed by ' default '. Stop.

In this case, the Linux system does not have prerequisites for installation

1 , Gcc--gnu Compiler Collection ( GCC You can use the default Package Manager's Warehouse ( repositories ) to install, the choice of package manager depends on what you use Linux the release version, the Package manager has different implementations: Yum is based on Red Hat version of the release; Apt used to Debian and the Ubuntu ; YaST used to SuSE Linux and so on. )

RedHat installed in GCC :

Yum Install GCC

Ubuntu installed in GCC :

Apt-get Install GCC

2 , PCRE Library ( Nginx Compilation Required PCRE ( Perl Compatible Regular Expression ), because Nginx of the Rewrite modules and HTTP the core module will use the PCRE the regular expression syntax. Two installation packages Pcre and pcre-devel need to be installed here . The first installation package provides a compiled version of the library, and the second provides the development phase of the header file and the source code of the compiled project, which is exactly the reason we need. )

RedHat installed in PCRE :

Yum Install Pcre Pcre-devel

Ubuntu installed in PCRE :

Apt-get Install Libpcre3 Libpcre3-dev

3 , zlib Library ( zlib The Library provides a developer's compression algorithm, Nginx need to be used in various modules of the gzip compression. Like installing PCRE , you also need to install the library and its source code:zlib and zlib-devel. )

RedHat installed in zlib :

Yum Install zlib Zlib-devel

Ubuntu installed in zlib :

Apt-get Install zlib1g Zlib1g-dev

4 , OpenSSL Library (in Nginx If the server provides a secure Web page, the OpenSSL Library, we need to install the library file and its development installation package ( OpenSSL and the Openssl-devel ). )

RedHat installed in OpenSSL :

Yum Install OpenSSL Openssl-devel

Ubuntu installed in OpenSSL : (Note: Ubuntu14.04 not found in the warehouse. Openssl-dev ):

Apt-get Install OpenSSL Openssl-dev

the Ngx_stream_upstream_module Module (1.9.0) is used to define groups of servers so can be referenced by the Proxy_pass directive.

Example Configuration

Backend {
Hash $remote _addr consistent;
Server backend1.example.com:12345 weight=5;
Server backend2.example.com:12345;
Server Unix:/tmp/backend3;
Server backup1.example.com:12345 backup;
Server backup2.example.com:12345 backup;
}
server {
Listen 12346;
backend;
}

For example: nginx.conf Detailed Configuration

http{

#虚拟主机1

server{

Listen 80;

server_name www.nginx1.com;

Location/{

root HTML;

Index index.html index.htm;

}

}

#虚拟主机2

server{

Listen 80;

server_name localhost;

Location/{

root HTML;

Index index.html index.htm;

}

}

}

Here server_name configuration domain name, if it is local test, need to WinDOS under the Hosts file, your domain name and IP added (C:\Windows\System32\drivers\etc\hosts)

Nginx supports three types of Virtual Host Configuration

    • 1. IP-based virtual host, (one host binds multiple IP addresses)

server{

Listen 192.168.1.1:80;

server_name localhost;

}

server{

Listen 192.168.1.2:80;

server_name localhost;

}

      • 2. Domain-based virtual host (ServerName)

#域名可以有多个, separated by a space

server{

Listen 80;

server_name www.nginx1.com www.nginx2.com;

}

server{

Listen 80;

server_name www.nginx3.com;

}

      • 3, Port-based virtual host (listen not write IP port mode)

server{

Listen 80;

server_name localhost;

}

server{

Listen 81;

server_name localhost;

}

Server under the Location Mapping Resolution (official Chinese document: Ngx_http_core_module ) Matching rules: Location [= | ~ | ~* | ^~] uri {...}

Location URI {}:

Takes effect on all objects under the current path and sub-path;

Location = URI {}:

Exactly matches the specified path (note that the URL is best for a specific path) and does not include sub-paths, so it only takes effect for the current resource;

Location ~ URI {}:

Location ~* URI {}:

The pattern-matching URI, where the URI can use regular expressions, ~ case-sensitive characters, ~* not distinguish between character case;

Location ^~ URI {}:

Regular expressions are no longer checked

Priority: = > ^~ > ~|~* >/|/dir/

Example:

Location =/{

[Configuration A]

}

Location/{

[Configuration B]

}

location/documents/{

[Configuration C]

}

Location ^~/images/{

[Configuration D]

}

Location ~* \. (Gif|jpg|jpeg) $ {

[Configuration E]

}

Answer: Request "/" match configuration A, request "/index.html" Match configuration B, request "/documents/document.html" Match configuration C, request "/images/1.gif" match configuration D, request "/DOCUMENTS/1". JPG "Matching configuration E

Location Configuration Rules

1, the "=" prefix of the instructions strictly match this query. If found, stop the search.
2. All the remaining regular strings, matching the most accurate (the longest one in general). If this match uses the ^? prefix, the search stops.
3, regular expression, in the configuration file is from the top down matching
4. If the 3rd rule produces a match, the result is used. Otherwise, as is used from the 2nd rule
Special cases:
In both cases, you do not need to continue to match the regular location:
(1) When the normal location in front of the designated "^~", specifically told Nginx this article general location once matched, you do not need to continue regular match.
(2) When the normal location is exactly the exact match, not the maximum prefix match, the matching regular is no longer maintained

In addition Nginx reverse proxy, Tengine (Nginx upgrade version) Health check also used location knowledge, you can go to see

Nginx Linux Installation Nginx

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.