Principes de base du serveur Web - Déploiement de l'environnement Nginx

Préface

Cet environnement est basé sur le système Centos 7.8 pour créer l'environnement d'apprentissage
Nginx Installer Nginx-1.18.0


Configuration requise

Système Centos 7.8:
cup: 2 * 2 RAM Disque dur 2G Mode réseau NAT 20G (accessible sur Internet) Installation basée sur MIni

1. Déploiement de Yum

Configurer la source nginx yum

[root@node01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true


[root@node01 ~]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.cqu.edu.cn
repo id                                repo name                                                       status
base/7/x86_64                          CentOS-7 - Base                                                 10,072
epel/x86_64                            Extra Packages for Enterprise Linux 7 - x86_64                  13,524
extras/7/x86_64                        CentOS-7 - Extras                                                  451
nginx-stable/7/x86_64                  nginx stable repo                                                  210
updates/7/x86_64                       CentOS-7 - Updates                                               1,640
repolist: 25,897

Installer nginx

[root@node01 ~]# yum install nginx -y

Démarrer le service nginx

[root@node01 ~]# systemctl enable --now nginx
[root@node01 ~]# netstat -lnutp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1495/nginx: master 

Accès au navigateur: http://192.168.5.11/
Insérez la description de l'image ici

2. Déploiement du code source

Installer et compiler les dépendances

[root@node02 ~]# yum install pcre-devel openssl-devel -y
[root@node02 ~]# yum install gcc gcc-c++ make -y

Téléchargez le package d'installation source et décompressez

[root@node02 ~]# ll
total 1020
-rw-------. 1 root root    1228 Jan 29 18:57 anaconda-ks.cfg
-rw-r--r--  1 root root 1039530 Apr 21  2020 nginx-1.18.0.tar.gz
[root@node02 ~]# tar xf nginx-1.18.0.tar.gz -C /usr/local/src/
[root@node02 ~]# cd /usr/local/src/nginx-1.18.0/
[root@node02 nginx-1.18.0]# ll
total 760
drwxr-xr-x 6 1001 1001    326 Feb 21 14:48 auto
-rw-r--r-- 1 1001 1001 302863 Apr 21  2020 CHANGES
-rw-r--r-- 1 1001 1001 462213 Apr 21  2020 CHANGES.ru
drwxr-xr-x 2 1001 1001    168 Feb 21 14:48 conf
-rwxr-xr-x 1 1001 1001   2502 Apr 21  2020 configure
drwxr-xr-x 4 1001 1001     72 Feb 21 14:48 contrib
drwxr-xr-x 2 1001 1001     40 Feb 21 14:48 html
-rw-r--r-- 1 1001 1001   1397 Apr 21  2020 LICENSE
drwxr-xr-x 2 1001 1001     21 Feb 21 14:48 man
-rw-r--r-- 1 1001 1001     49 Apr 21  2020 README
drwxr-xr-x 9 1001 1001     91 Feb 21 14:48 src

Compiler et installer

[root@node02 nginx-1.18.0]# ./configure --user=nginx --group=nginx \
> --prefix=/usr/local/nginx \
> --with-http_ssl_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_auth_request_module \
> --with-http_stub_status_module

[root@node02 nginx-1.18.0]# make
[root@node02 nginx-1.18.0]# make install

Créer des utilisateurs et des groupes

[root@node02 ~]# groupadd -r -g 995 nginx
[root@node02 ~]# useradd -r -g 995 -u 995 -M -s /sbin/nologin nginx

Fournir un script de service de démarrage du système

[root@node02 nginx-1.18.0]# vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target

Ajouter des variables d'environnement nginx

[root@node02 ~]# vim /etc/profile.d/nginx.sh
export PATH=$PATH://usr/local/nginx/sbin/
[root@node02 ~]# source /etc/profile.d/nginx.sh

Démarrer le service, afficher l'état du service

[root@node02 nginx-1.18.0]# systemctl daemon-reload
[root@node02 nginx-1.18.0]# systemctl enable --now nginx
[root@node02 nginx-1.18.0]# netstat -lnutp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4295/nginx: master

Accès au navigateur: http://192.168.5.12/
Insérez la description de l'image ici

Je suppose que tu aimes

Origine blog.csdn.net/XY0918ZWQ/article/details/113917243
conseillé
Classement