Nginx Linux deployment

In the past, there were always some problems in the deployment process. Each time, I wasted time searching for solutions. This time, I recorded the deployment steps of the new server for future reference

1. Environment preparation

GCC, make, wget, and g++ have been installed on the server

yum -y install gcc-c++
Copy the code

Nginx relies on the following modules: the zlib library for the gzip module, the PCRE library for the rewrite module, the OpenSSL library for the SSL function, and a one-click installation

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
Copy the code

Or directly download the specified version and create a new directory for storing it

Openssl is used to encrypt SSL modules and supports HTPS

Wget HTTP: / / https://www.openssl.org/source/openssl-1.0.2s.tar.gzCopy the code

Download pcRE to implement support for address redirection, address rewriting and localtion instructions and regular expressions

Wget HTTP: / / https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gzCopy the code

Download the Zlib gzip compression module

Wget HTTP: / / https://zlib.net/zlib-1.2.11.tar.gzCopy the code

Download Nginx or nginx.org/en/download…

Wget HTTP: / / http://nginx.org/download/nginx-1.17.1.tar.gzCopy the code

Use tar to unzip all files into the save directory

ls *.tar.gz | xargs -n1 tar xzvf  
Copy the code

2. Use configure to configure Nginx

You can select configuration information and do not choose to install as the default configuration.

 	--prefix   // Installation path
    --sbin-path  // Executable file installation path
    --conf-path   // Configuration file path
    --pid-path    // Place the PID path
    --lock-path   //nginx.lock place path
    --error-log-path   // Error log path
    --http-log-path    // Access log path
    --user             // Start the user
    --group            / / start a group
    --builddir         // Specify the directory to compile
    --with-rtsig_module   // Start rTSIg module
    --with-select-module   // SELECT mode is enabled or not
    --with-poll_moduel     Poll mode is enabled or not
    --with-http_ssl_module   // Enable the http_ssl module
    --with-http_realip_module 
    --with-http_addition_module 
    --with-http_dav_module
    --with-http_flv_module
    --with-stub_status_module
    --without-http_charset_module
    --without-http_gzip_module
    --without-http_ssl_module 
    --without-http_userid_module
    --without-http_access_module
    --without-http_auth_basic_module
    --without-http_autoindex_module
    --without-http_geo_module
    --without-http_map_module
    --without-http_referer_module
    --without-http_rewrite_module
    --without-http_proxy_module
    --without-http_fastcgi_module
    --without-http_memcached_module
    --without-http_limit_zone_module
    --without-http_empty_gif_module
    --without-http_browser_module
    --without-upstream_ip_hash_module
    --with-http_pcel_module
    --with-perl=PATH             // Specify the PERL module path
    --with-log-path              // Log access path
    --http-client-body-temp-path     // Request the cache file
    --http-proxy-temp-path           // Reverse proxy cache file
    --http-fastcgi-temp-path         //fastcgi cache file path
    --without-http                   / / disable httpserver
    --with-mail                 // Enable the IMAP4/POP3/SMTP proxy mode--with-mail_ssl_module --with-cc specifies the path to the C compiler --with-cpp specifies the path to the C preprocessor --with-cpu-opt compiles for a specific CPU -- with-pcre disables pcRE --with-pcre Specifies the source code path of the PCRE library. --with-pcre-opt sets additional compiler options of the PCRE. --with-md5 specifies the source code path of the MD5 libraryasm--with-shal- set the shal library source code path --with-shal-asm--with-zlib-opt --with-zlib-opt --with-zlib-opt --with-zlib-optasm--with-openssl set openSSL source path --with-openssl-option Set OpenSSL source path --with-debug Start debug log --add-moduleAdd a specified path to find third-party modulesCopy the code

Install according to custom

./configure \ --with-openssl=.. /openssl-1.0.2s \			// Custom installed OpenSSL, since modules are all in the same directory--with-pcre=.. /pcre-8.43 \					// Custom installed PCRE--with-zlib=.. /zlib-1.211. \					// Customize the zlib installation
   --with-pcre-jit --user=admin \				/ / admin
   --prefix=/home/admin/nginx \					// Install in a local directory
   --with-http_ssl_module \						//https
   --with-http_v2_module 						//http

Copy the code

If the following information is displayed, the configuration is correct

Configuration summary + using PCRE library: .. /pcre-8.43+ using OpenSSL library: .. /openssl-1.0.2s + using zlib library: .. /zlib-1.211.

  nginx path prefix: "/usr/local/src/nginx/nginx"
  nginx binary file: "/usr/local/src/nginx/nginx/sbin/nginx"
  nginx modules path: "/usr/local/src/nginx/nginx/modules"
  nginx configuration prefix: "/usr/local/src/nginx/nginx/conf"
  nginx configuration file: "/usr/local/src/nginx/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/src/nginx/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/src/nginx/nginx/logs/error.log"
  nginx http access log file: "/usr/local/src/nginx/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
Copy the code

3. Compile and install

compile

make
Copy the code

The installation

make install
Copy the code

Configure permissions

Nginx is not allowed to use ports below 1024 for Linux users. Assign nginx to user root, then assign special privileges

sudo chown root nginx
sudo chmod u+s nginx
Copy the code

Or release the first line comment in the configuration file

user nobody;

4. Installation problems

Check whether the installation environment is completeCopy the code

5. Common commands

1. Specify a configuration file for startup

//nginx sbin directory == Configuration file location
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Copy the code

2. Reload the file

/ / nginx sbin directory
/usr/local/nginx/sbin/nginx -s reload
Copy the code

3. Reload the configuration file

//nginx sbin directory == Configuration file location
/usr/local/nginx/sbin/nginx -t /usr/local/nginx/conf/nginx.conf
Copy the code

4. Stop

/ / nginx sbin directory
/usr/local/nginx/sbin/nginx -s stop
Copy the code

5. Check whether the configuration is correct

/ / nginx sbin directory
/usr/local/nginx/sbin/nginx -t
Copy the code

5. The violence stops

/ / nginx sbin directory
/usr/local/nginx/sbin/nginx -s stop
Copy the code

6. Stop gracefully

/ / nginx sbin directory
/usr/local/nginx/sbin/nginx -s quit
Copy the code