在CentOS7上安装和配置Nginx
使用yum进行安装。
如果只用作Web服务器,可以很容易地通过yum进行安装。
インストール
yum install nginx
確認
nginx -v
設定ファイルの場所
cd /etc/nginx
起動
systemctl start nginx
終了
systemctl stop nginx
OS起動時に起動するようにする
systemctl enable nginx
OS起動時に起動しないようにする
systemctl disable nginx
用yum进行(最新版)安装
通过使用官方的软件库,可以安装最新版本的nginx,而上述方法却安装了旧版本的nginx。
添加存储库
sudo vi /etc/yum.repos.d/nginx.repo
请将以下内容填写在纸上。
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
安装Nginx。
sudo yum install nginx
确认版本
nginx -v
自动启动设置
sudo systemctl enable nginx
启动
sudo systemctl start nginx
从源代码安装
如果需要安装特殊的模块,则需要从源代码进行安装。
在nginx中,没有动态库,只有静态库,因此如果需要必要的外部模块,则需要从源代码进行安装。
這次的情況是安裝了 RTMP 模組。
ダウンロード
wget http://nginx.org/download/nginx-1.13.5.tar.gz
tar -zxvf nginx-1.13.5.tar.gz
rtmpモジュールの取得
git clone https://github.com/arut/nginx-rtmp-module
cd nginx-1.13.5
./configure --with-http_ssl_module --with-http_realip_module --with-http_v2_module --add-module=../nginx-rtmp-module-master
make
make install
起動
sudo /usr/local/nginx/sbin/nginx
設定ファイル
vi /usr/local/nginx/conf/nginx.conf
再読み込み
/usr/local/nginx/sbin/nginx -s reload
終了
/usr/local/nginx/sbin/nginx -s stop
自動起動設定
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
RemainAfterExit=yes
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nginx