環境
操作系統:CentOS7
服務器地址:192.168.142.101
Yum version: 3.4.3
源碼安裝
-
安裝依賴
yum -y install gcc pcre-devel zlib-devel openssl-devel
-
下載安裝包
http://nginx.org/download/ -
上傳服務器並解壓,解壓路徑爲/data/soft
tar -zxvf nginx-1.19.0.tar.gz -C /data/soft
-
進入解壓路徑,執行configure腳本
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
-
編譯及安裝
make && make install
官方YUM源安裝
常用的模塊已經被默認指定,安裝較爲簡單
-
配置官方的YUM源
touch /etc/yum.repos.d/nginx.repo
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
-
查看當前的yum倉庫
yum repolist
-
yum安裝nginx
yum install -y nginx
-
查看nginx信息
nginx -V
幾個重要文件
- Nginx主配置文件
/etc/nginx/nginx.conf - Nginx配置文件
/etc/nginx/conf.d/*.conf - Nginx日誌文件路徑
/var/log/nginx
運行
-
檢測配置文件語法是否正確
nginx -t
-
運行
systemctl start nginx
或:
systemctl reload nginx
-
檢驗