nginxをインストールする方法については、主にyumでインストールとソースコンパイルでインストールです。今回はこの二つ方法を紹介いたします。
方法1:ソースコンパイルでインストール
依存ライブラリをインストール
yum -y install pcre-devel
ソースコードをダウンロード
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.15.8.tar.gz
wget http://nginx.org/download/nginx-1.15.8.tar.gz
コンパイルとインストール
tar -zxvf nginx-1.15.8.tar.gz
./configure –with-http_ssl_module –prefix=/usr/local/nginx
make
make install
./configure –with-http_ssl_module –prefix=/usr/local/nginx
make
make install
自動起動するため、起動スクリプトの設定
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx – high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit]
Description=nginx – high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
起動スクリプトの確認
Nginx起動
systemctl start nginx
Nginx停止
systemctl stop nginx
Nginx自動起動
systemctl enable nginx
systemctl start nginx
Nginx停止
systemctl stop nginx
Nginx自動起動
systemctl enable nginx
方法2:yumでインストール
yumの更新
sudo yum update
Nginxのインストール
sudo yum install nginx
Nginxの確認
nginx -v
Nginxの起動
sudo service nginx start
Nginxの再起動
sudo service nginx restart
Nginxの停止
sudo nginx -s stop