Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

Nginx installation and deployment documentation

Create a Linux server user

If the following command is not executed

 useradd ksquant
 groupadd docker
 usermod -aG docker ksquant
 passwd ksquant
 su - ksquant
 cd /home/ksquant
 mkdir mysql
 mkdir nginx
 mkdir qtserver
 mkdir images
 mkdir rpm
Copy the code

I. Docker deployment mode

The server can connect to the Internet

  1. Create a specified directory
 mkdir -p /home/ksquant/nginx/html
 mkdir -p /home/ksquant/nginx/config
 mkdir -p /home/ksquant/nginx/logs
 cd /home/ksquant/nginx/config   
Copy the code
  1. Creating a Configuration File
 vi default.conf
Copy the code

Configuration file Contents

server { listen 80; listen [::]:80; server_name localhost; client_max_body_size 10m; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /data { root /usr/share/nginx/html; } location /quant { root /usr/share/nginx/html; index index.html index.htm; } the location/entry {proxy_pass http://10.253.49.103:9030/; } #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 /usr/share/nginx/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; #}}Copy the code
  1. Execute docker to install nginx
Docker run -p 80:80 --restart=always --net app -- IP 172.16.1.5 --log-driver=json-file --privileged=true --name nginx-v /home/ksquant/nginx/html:/usr/share/nginx/html -v /home/ksquant/nginx/config/:/etc/nginx/conf.d/ -v /home/ksquant/nginx/logs:/var/log/nginx/ -d nginxCopy the code
  • -p 80:80: specifies the host port and container port. (Optional configuration)
  • Net app: specifies the docker network. App is the network created when docker is installed. (Optional configuration)
  • — IP 172.16.1.5: Specifies the IP address of MySQL in the Docker network app. 172.16.1.5 is related to the network segment specified when the app is created.
  • – v/home/docker/nginx/HTML: / usr/share/nginx/HTML: static resource directory mounted; /home/docker/nginx/ HTML is the address in the host; /usr/share/nginx/html is the address of the container’s internal configuration file
  • – v/home/ksquant/nginx/config / : / etc/nginx/conf., d/a: configuration file directory mounted;
  • – v/home/ksquant/nginx/logs: / var/log/nginx/log directory mount
  • –restart=always: indicates that when docker restarts, the container automatically starts
  • -d: indicates background startup
  • –name nginx: Specifies the container name
  • — Privileged =true: Privileged the container
  • –log-driver=json-file: Specifies the log file type when the container is started

The server cannot connect to the Internet

  1. Create a specified directory
 mkdir -p /home/ksquant/nginx/html
 mkdir -p /home/ksquant/nginx/config
 mkdir -p /home/ksquant/nginx/logs
Copy the code
  1. upload05 Deploying Documents \04 Software PackagesThe nginx image compressed file nginx.tar is stored in the directory/home/ksquant/images
  2. Run the following command to load the nginx image into the Docker local image repository
 cd /home/ksquant/images
 docker load -i nginx.tar
Copy the code
  1. Creating a Configuration File
 cd /home/ksquant/nginx/config
 vi default.conf
Copy the code
server { listen 80; listen [::]:80; server_name localhost; client_max_body_size 10m; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /data { root /usr/share/nginx/html; } location /quant { root /usr/share/nginx/html; index index.html index.htm; } the location/entry {proxy_pass http://10.253.49.103:9030/; } #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 /usr/share/nginx/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; #}}Copy the code
  1. Execute the command
Docker run -p 80:80 --restart=always --net app -- IP 172.16.1.5 --privileged=true --name nginx-v /home/ksquant/nginx/html:/usr/share/nginx/html -v /home/ksquant/nginx/config/:/etc/nginx/conf.d/ -v /home/ksquant/nginx/logs:/var/log/nginx/ -d nginxCopy the code
  • -p 80:80: specifies the host port and container port. (Optional configuration)
  • Net app: specifies the docker network. App is the network created when docker is installed. (Optional configuration)
  • — IP 172.16.1.5: Specifies the IP address of MySQL in the Docker network app. 172.16.1.5 is related to the network segment specified when the app is created.
  • – v/home/docker/nginx/HTML: / usr/share/nginx/HTML: static resource directory mounted; /home/docker/nginx/ HTML is the address in the host; /usr/share/nginx/html is the address of the container’s internal configuration file
  • – v/home/ksquant/nginx/config / : / etc/nginx/conf., d/a: configuration file directory mounted;
  • – v/home/ksquant/nginx/logs: / var/log/nginx/log directory mount
  • –restart=always: indicates that when docker restarts, the container automatically starts
  • -d: indicates background startup
  • –name nginx: Specifies the container name
  • — Privileged =true: Privileged the container (optional)

2. Native deployment mode

  1. Yum installs several environment dependencies
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
Copy the code
  1. Creating an installation directory
mkdir -p /home/ksquant/app
cd /home/ksquant/app
Copy the code
  1. Download the nginx source code, or upload it if you cannot connect to the network05 Deploying Documents \04 Software PackagesGz file to /home/ksquant/app and go to Step 4
Wget HTTP: / / http://nginx.org/download/nginx-1.14.2.tar.gzCopy the code
  1. Start the installation
Tar -xzvf nginx-1.14.2.tar.gz CD nginx-1.14.2. /configure --prefix=/home/ksquant/app/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre make && make installCopy the code
  1. Nginx is installed in the /home/app/nginx directory
ls /home/ksquant/app/nginx
Copy the code