RPM-IVH https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm
# Install Ali's Epel source
Domestic use of the most web site WWW service is Nginx
Official website: nginx.org
What is Nginx ?
Open source, support high-performance, high-concurrency WWW service software, an implementation of HTTP protocol
Advantages:
High concurrency (static resources)
Consume less resources
Feature rich (reverse proxy, load balancer)
Efficient and stable
Nginx What are the applications?
- Classic Combo LAMP (Linux apache MySQL php)
- Now Combo: lnmp (linux nginx mysql php)
- Web services software, with reverse proxy function, stable and efficient operation
- Can run on any known platform
Nginx overall why is it better than Apache High performance?
1. Nginx uses the Epoll IO model, while Apache uses the traditional select IO model
2. Epoll is more efficient for sites that require high concurrency
Nginx What are the common modules?
1. Nginx Core Module
Responsible for Nginx global application, the main block and events block of the corresponding configuration file, including the global parameter configuration required by Nginx.
2. standard set of HTTP function modules
Default automatic installation to Nginx, not recommended changes by default, the software default configuration is generally the best
how to compile and install Nginx ?
Before installing the first understand these questions, choose what version? What is the Select installation directory? Where do I put the download package? Installation of Nginx software related dependencies
Here follow the http://www.cnblogs.com/2bjiujiu/p/8067201.html policy to select the version, and the other nodes in the Web cluster use this version uniformly, select any one of the stable version
Any installation through the compilation of installation directory uniform provisions placed in the/application directory
As a rule, the packages downloaded from the website are placed in the tools directory under the current user home directory
2. installation of Nginx software related dependencies
Install dependent software: Pcre pcre-devel OpenSSL Openssl-devel
Yum install-y pcre pcre-devel OpenSSL openssl-devel# pcre Library, developed regular, in order to support nginx URL rewrite rewrite module # OpenSSL library, secure encryption related libraries
3. Download and Unzip
mkdir ~/tools # Create a directory for the unified download package CD ~/tools # cut into this directory wget-q http://nginx.org/download/nginx-1.12.2.tar.gz # Download Source Package tar-xf nginx-1.12.2.tar.gz # unzip the CD nginx-1.12.2 # Enter the source package
4. Hide Nginx Package Information
1. Change the Nginx software name
Vim src/core/nginx.h # Modify global parameters #define Nginx_version "1.12.2" # Change version # to Apache latest version number, Confusing #define Nginx_ver "nginx/" nginx_version # More Change NGINX, changed to www #define Nginx_var "Nginx" # change Nginx, this is the software name, changed to www
Vim src/http/ngx_http_header_file_module.c - static U_char ngx_http_server_string[] = "Server:nginx" CRLF ; # change 49 Lines "Server:nginx" to "server:www" # Note the spaces and formatting
2. Change the error message
Vim src/http/ngx_http_special_response.c 36 line "
3. Add software to run the user, compile and install
Useradd web_nginx-s/sbin/nologin-m # Add Web_nginx run User ID web_nginx # check./configure--user=web_nginx--group= Web_nginx--with-http_ssl_module--with-http_stub_status_module--prefix=/application/nginx-1.12.2/ #--user= and --group= specifies what identity to run #--WITH-HTTP_SSL_MODULE provides the necessary support for HTTPS and requires the OpenSSL Library #--with-http_stub_status_module to provide access to basic state information #- -prefix= Specify the installation path, you need to specify a Nginx source package name directory, make the version number to differentiate made && do install # compile and install
4. Create a soft link
Ln-s/application/nginx-1.12.2//application/nginx# Remove the version number, but development does not need to focus on the version information, software upgrades, for development without any impact # software calls, do not need a relationship version number, Software upgrades also do not affect development and software calls
5. Testing
1. Start Nginx
/application/nginx/sbin/nginx-t # Check that the configuration file is correct/application/nginx/sbin/nginx # startup Nginxnetstat-lntup | grep 80 # Check
2. Check
Open browser Access host_ip # Access host extranet IP address # If the Return Nginx Welcome page indicates Nginx installation succeeded Curl-i host_ip # Check if the version number and version information are hidden
Nginx What are the errors that may occur during installation?
1. Start Nginx Error, Nginx: [Emerg] Getpwnam ("Web_nginx") faild
Cause: No user added nginx operation required
Workaround: Useradd web_nginx-s/sbin/nologin-m
2. The compilation process error, GCC not all caused errors
Workaround: Yum install-y gcc-c++
3. Check that the system is initializing when the base package is installed
Yun grouplist # View installed packages # focus on the following packages if not installed via Yum groupinstall-y "package name" Install # base# compatibility libraries# debugging Tool s# Development Tools
4. Check the service local ports, processes, and URLs
Lsof-i: Check port 80 for service Ps-ef | grep nginx # Check if there is an Nginx process # check if the browser input host address is correct, is not the host external network IP, port connection symbol is English format
5. Viewing error log information
Its log file path:/application/nginx/logs/error.log# premise is the Nginx installation directory specification for/application and soft links established correctly # cat/application/nginx/logs/ Error.log
Web Troubleshooting Service Errors
1. Client Ping server IP address
Ping 10.0.0.8 # Troubleshooting physical Lines
2. Telnet Server IP address on client
Telnet 10.0.0.8 80 # Exclude firewall failure
3. liunx Client Check
Curl 10.0.0.8 # Simulate browser request
# wget 10.0.0.8 will download the webpage
Nginx configuration file Parameters
Location:/application/nginx/conf/nginx.conf
Worker_processes # Number of processes
Events # Model
Worker_connections # Maximum number of connections for a process connection
HTTP # HTTP-related configuration
Include # contains configuration file keywords
Sendfile # Efficient Distribution mode
Keepalive_timeout # A live connection hold time
Server # Virtual host, corresponding to a site
Listen # Listening Port
SERVER_NAME # domain name, separated by multiple intermediate spaces
Location # matches the field after the domain name
Root # Site root directory
Index # return home address
Error_page # error page information
What is a virtual host?
a server dictionary in the configuration file
A stand-alone site in a Web server that corresponds to a separate domain name (or possibly an IP or port), has a separate program and resource directory, and can be serviced independently to provide access to the user
There are three categories
1. Domain Name
The most extensive, the application of external Web sites, through the request header to differentiate, direct IP address access, the default first virtual host, in the HTTP module, multiple servers will have multiple virtual host, through the domain name to differentiate the host
2. Ports
Apply to the inside of the company, the website backstage, through the port to differentiate the host
3. IP
Secondary IP is not supported, almost no
What is the change profile principle?
1. Back up the original file, the format is: the original configuration Name _ time _ Modified version number, this is the specification
/application/nginx/conf/nginx.conf{,._$ (date +%f) _V1}
2. Any individual modifications completed, the second modification needs to be backed up once, version number +1
3. There is a check error method, first call the check, usually the-t parameter
4. Service graceful Restart via reload
5. Error immediately rollback, back to previous version
How to implement resource download display?
- In the corresponding server, add AutoIndex on; field, in the case of access to no resources, will be listed in the root directory of this resource, all the content will be available for download. Normal does not have this parameter, will prompt 403 error
Nginx How do I configure multiple sites?
- For multiple sites, multiple servers are required and are written in the master configuration file and are not very professional
- Under the Conf configuration directory, create the extra directory to hold the site server
- Add include extra/*.conf in master Config file http, unified include extra in configuration
Nginx Status View
Vim extra/status.conf # Add Nginx State virtual machine server{ listen; server_name status.benmenchuixue.com location/beimen { stub_status on; Access_log off; #allow 172.16.1.0 set Allow access to the IP segment #deny All, disable access to }}# restart Nginx, and then access this domain name implementation to get NGINX status # Here Joint monitoring use, if the user directly access IP, Jump to the home page via Rewrit, if there is a special mark in the following # knowledge will match to return status information # Note that the HTML directory index.html and 50x.html will expose the software version information, need to do the information desensitization processing of these two files, remove the feature information display
How to prevent users from directly passing IP access the server?
Vim forbid_ip.conf # Write Content server { listen default; server_name _; return 500;} # Direct IP access, return 500 error
Linux_nginx Environment Configuration