Webサーバーの基本-Nginx環境の展開

序文

この環境は、Nginx学習環境を構築するためのCentos7.8システムに基づいてい
ますNginx-1.18.0をインストールします


システム要求

Centos 7.8システム:
カップ:2 * 2 RAM2Gハードディスク20GNATネットワークモード(インターネットにアクセス可能)MIniに基づくインストール

1.Yumデプロイメント

nginxyumソースを構成します

[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

nginxをインストールします

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

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 

ブラウザアクセス:http://192.168.5.11/
ここに画像の説明を挿入

2.ソースコードの展開

依存関係をインストールしてコンパイルする

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

ソースインストールパッケージをアップロードして解凍します

[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

コンパイルしてインストール

[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

ユーザーとグループを作成する

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

システム起動サービススクリプトを提供する

[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

nginx環境変数を追加します

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

サービスを開始し、サービスステータスを表示します

[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

ブラウザアクセス:http://192.168.5.12/
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/XY0918ZWQ/article/details/113917243