NGINX官網
以下列舉了三個網址,分別是:NGINX官網,下載網址及官方文檔。
官方網站:http://nginx.org/
下載網址:http://nginx.org/en/download.html
官方文檔:http://nginx.org/en/docs/
下載NGINX
通過官方下載地址,可獲得nginx源碼包。
在windows中下載,其中NGINX分爲Linux版本和Windows版本,按照需求下載相應版本的NGINX即可。
Linux下載,直接右擊Linux對應的NGINX,右擊複製鏈接地址,之後在Linux中通過wget命令下載即可。
wget http://nginx.org/download/nginx-1.19.0.tar.gz
安裝環境
注:網絡yum源或本地yum源都可。
通過軟件倉庫安裝NGINX所需的依賴包
yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel make automake
若是Linux自身的網絡yum源下載緩慢,可通過==>配置國內yum源地址<==轉用國內yum源。
創建NGINX服務用戶,負責程序的正常運行。
groupadd www
useradd -g www www -s /sbin/nologin
解壓,編譯,安裝
解壓
tar zxf nginx-1.19.0.tar.gz
cd nginx-1.19.0/
預編譯
注:列舉了一些較爲常用模塊,詳細可查看NGINX官方文檔
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
配置項說明:
–prefix:nginx安裝路徑
–with-http_dav_module:通過WebDAV協議提供文件管理自動化,默認情況下未構建此模塊。
–with-http_stub_status_module:提供對NGINX基本狀態信息的訪問,默認情況下未構建此模塊。
–with-http_addition_module:過濾器,可在響應之前和之後添加文本,默認情況下未構建此模塊。
–with-http_sub_module:允許一些其他字符串替換NGINX中的指定字符串來修改相應,默認情況下未構建此模塊。
–with-http_flv_module:爲Flash Video(FLV)文件提供僞流服務器端支持,默認情況下未構建此模塊。
–with-http_mp4_module:該 模塊爲MP4文件提供僞流服務器端支持,默認情況下未構建此模塊。
–with-pcre:強制使用PCRE庫。
–with-http_ssl_module:啓用構建將HTTPS協議支持添加 到HTTP服務器的模塊的功能,默認情況下未構建此模塊,需要OpenSSL庫來構建和運行此模塊。
–with-http_gzip_static_module:支持發送.gz擴展名爲" "的預壓縮文件,而不是常規文件,默認情況下未構建此模塊。
–user:NGINX服務運行使用的用戶,默認用戶名爲nobody。
–group:NGINX服務運行使用的組,默認情況下爲nginx運行用戶的名稱。
預編譯完成後,查看是否執行成功
echo $?
0 #除0外的任何值都表示沒有執行成功
編譯並安裝
make ; make install
啓動及測試
安裝完成後,就可以通過nginx的控制腳本啓動了。
控制腳本的名稱爲nginx,路徑位於/usr/local/nginx/sbin/nginx。可以看到其位於nginx的sbin目錄下,其表示除管理員用戶外,其他用戶無法啓動,除非是由其他用戶進行的編譯安裝。
爲NGINX控制腳本設置PATH變量
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
查看nginx控制腳本命令幫助
nginx -h
nginx version: nginx/1.19.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
一些常用的NGINX控制語句:
nginx -t:檢測配置文件語法是否出錯
nginx:啓動NGINX服務
nginx -s stop:關閉NGINX服務
nginx -s reload:重載NGINX配置(在nginx配置文件修改時使用)
啓動NGINX
nginx
查看端口是否存在
netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5774/nginx: master
訪問測試
curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
以上就是NGINX安裝全過程。