I. Installation of Nginx
1. pcre Dependent Installation
Official download: Download version 8.37 here for pcre-8.37.tar.gz is uploaded to the linux machine.
https://sourceforge.net/p/pcre/activity/?page=0&limit=100#5a81db4a5fcbc934232f5f55
#decompression tar zxvf pcre-8.37.tar.gz cd pcre-8.37 #Inspection and installation ./configure make && make install #Verify successful installation pcre-config --version
Successful installation is illustrated below
2. openssl, zlib Dependent Installation
#Perform a one-time yum installation yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
If a "Multilib version problems found." error occurs, add "--setopt=protected_multilib=false" as prompted.
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel --setopt=protected_multilib=false
It should be ok without obvious error.
3. Installation and Startup of Nginx
(1) Official Web Download the corresponding version
#Version 1.12.2 is downloaded here wget http://nginx.org/download/nginx-1.12.2.tar.gz #Decompression: tar zxvf nginx-1.12.2.tar.gz #install cd nginx-1.12.2 ./configure make && make install
The following is normal installation:
There are more nginx directories in the /usr/local path after installation.
There is an executable file nginx in the sbin directory of cd nginx; This is the executable that starts nginx.
(2) Startup
(4)start-up nginx cd /usr/local/nginx/sbin ./nginx
4. Verify successful installation
(1) Check to see if the process is ok, as follows is expected.
(2) Browser access validation
In nginx/conf/nginx.conf, you can see that it listens on port 80 by default, as follows:
Note:. /conf/nginx.conf is the configuration file for nginx.
Browser We enter the public ip of the target Linux machine directly, and the following effect indicates that the deployment was successful.
5. Notes
Situation 1: If it is a cloud server, you may want to open port 80 in the security group;
Situation 2: If you turn on the firewall, you also need to stay down and open the corresponding ports to the firewall.
For firewall configuration commands see Firewall-related commands_ Blanking Blog - CSDN Blog
2. Common Nginx commands
Preface: The precondition of using nginx operation command is that it must enter the directory of nginx.
cd /usr/local/nginx/sbin
2. Common Commands
#View nginx version number ./nginx -v #start nginx ./nginx #Close nginx ./nginx -s stop #Reload nginx (if you modify the configuration in nginx.conf and do not want to restart nginx to perform the reload) ./nginx -s reload
3. Configuration files for Nginx
Foreword: The configuration file path of nginx is /usr/local/nginx/conf/nginx.conf
The nginx file consists of three main parts:
1. Part 1: Global Blocks
From the beginning of the configuration file to the events block, there are some configuration instructions that affect the overall operation of the nginx server. This includes configuring the users (groups) running the Nginx server, the number of worker preocess allowed to be generated, the process PID storage path, the log storage path and type, and the introduction of configuration files. For example:
worker_processes 1;
This is the key configuration for the Nginx server concurrent processing service, worker_ The larger the precesses value, the more concurrent processing can be supported. Note: However, it will be limited by hardware, software and other devices.
2. Part Two: Evets Block
Evets block mainly affects the network connection between the Nginx server and the user. Common settings include whether to open a serialized network connection under multiple work processes, whether to run and allow multiple network connections at the same time, which time-driven model to handle connection requests, and the maximum number of connections each work process can support at the same time. The following:
worker_connections 1024;
Indicates the maximum number of links supported per work process is 1024.
Note: This part of the configuration has a great impact on the performance of Nginx, so it should be flexibly configured in practice
3. Part 3: http Blocks
The parts of the Nginx server that are most frequently configured. It has two parts: http global fast, server block.
(1) http global block
Directives for http global fast configuration include file introduction, MIME-TYPE definition, log customization, connection timeout, maximum number of single link requests, etc.
(2) server block
Closely related to the virtual host. From a user's perspective, a virtual host is the same as a separate physical host.
Each http block can contain multiple server blocks, and each server block is equivalent to a virtual host.
Each server block is also divided into global server blocks, and the first level can contain multiple location blocks at the same time.
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }