02.Nginx安裝和目錄文件詳解

Nginx安裝

Nginx版本描述:

Mainline version 開(kāi)發(fā)版
Stable version 穩(wěn)定版
Legacy version 歷史版本

基礎(chǔ)環(huán)境準(zhǔn)備:
確認(rèn)系統(tǒng)網(wǎng)絡(luò)

[root@Nginx ~]# ping baidu.com

關(guān)閉firewalld

[root@Nginx ~]# systemctl stop firewalld
[root@Nginx ~]# systemctl disable firewalld

臨時(shí)關(guān)閉selinux

[root@Nginx ~]# setenforce 0

初始化基本目錄

[root@Nginx ~]# mkdir /soft/{code,logs,package,backup} -p

基本安裝包

[root@Nginx ~]# yum install -y gcc gcc-c++ autoconf  pcre pcre-devel make automake wget httpd-tools vim tree

配置Nginx官?方Y(jié)um源
官方文檔安裝步驟: http://nginx.org/en/linux_packages.html

[root@Nginx ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

安裝Nginx

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

查看Nginx當(dāng)前版本

[root@Nginx ~]# nginx -v
nginx version: nginx/1.12.2

Nginx安裝目錄

[root@Nginx ~]# rpm -ql nginx

如下對(duì) Nginx 安裝目錄做詳細(xì)概述

配置?文件Nginx主配置?文件
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf

配置文件Cgi、Fastcgi叠赦、Uwcgi配置文件
/etc/nginx/fastcgi_params
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params

配置文件Nginx編碼轉(zhuǎn)換映射文件
/etc/nginx/win-utf
/etc/nginx/koi-utf
/etc/nginx/koi-win

配置文件http協(xié)議的Content-Type與擴(kuò)展名
/etc/nginx/mime.types

配置文件配置系統(tǒng)守護(hù)進(jìn)程管理器
/usr/lib/systemd/system/nginx.service

配置文件Nginx日志輪詢(xún),日志切割
/etc/logrotate.d/nginx

命令Nginx終端管理命令
/usr/sbin/nginx
/usr/sbin/nginx-debug

目錄Nginx模塊目錄
/etc/nginx/modules
/usr/lib64/nginx
/usr/lib64/nginx/modules

目錄Nginx默認(rèn)站點(diǎn)目錄
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html

目錄Nginx的幫助手冊(cè)
/usr/share/doc/nginx-1.12.2
/usr/share/man/man8/nginx.8.gz

目錄Nginx的緩存目錄
/var/cache/nginx

目錄Nginx的日志目錄
/var/log/nginx

Nginx編譯參數(shù)

查看Nginx編譯參數(shù)

[root@Nginx ~]# nginx -V

下表展示了Nginx編譯參數(shù)選項(xiàng)以及作用


image.png

image.png

Nginx常用模塊

Nginx模塊分為 Nginx官方模塊以及Nginx第三方模塊


image.png

image.png

Nginx內(nèi)置變量

http核心模塊的內(nèi)置變量

http請(qǐng)求變量
Nginx內(nèi)置變量
自定義變量量

$uri: 當(dāng)前請(qǐng)求的uri驹马,不帶參數(shù)
$request_uri: 請(qǐng)求的uri,帶完整參數(shù)
$host: http請(qǐng)求報(bào)文中host?部,如果沒(méi)有則以處理此請(qǐng)求的虛擬主機(jī)的主機(jī)名代替
$hostname: nginx服務(wù)運(yùn)行在主機(jī)的主機(jī)名
$remote_addr: 客戶(hù)端IP
$remote_port: 客戶(hù)端口
$remote_user: 使用戶(hù)認(rèn)證時(shí)客戶(hù)端用戶(hù)輸入的用戶(hù)名
$request_filename: 用戶(hù)請(qǐng)求中的URI經(jīng)過(guò)本地root或alias轉(zhuǎn)換后映射的本地文件路徑
$request_method: 請(qǐng)求方法, GET POST PUT
$server_addr: 服務(wù)器地址
$server_name: 服務(wù)器名稱(chēng)
$server_port: 服務(wù)器端口
$server_protocol: 服務(wù)?向客戶(hù)端發(fā)送響應(yīng)時(shí)的協(xié)議, 如http/1.1 http/1.0
$scheme:在請(qǐng)求中使?用scheme, 如http://xxx.com中的http
$http_HEADER: 匹配請(qǐng)求報(bào)文中指定的HEADER
$http_host: 匹配請(qǐng)求報(bào)文中的host?首部
$document_root: 當(dāng)前請(qǐng)求映射到的root配置

Nginx編譯安裝

openresty編譯安裝
1.基礎(chǔ)環(huán)境準(zhǔn)備

mkdir /soft/package/src -p
mkdir /soft/package/src/ngx_3rd -p
useradd -s /sbin/nologin -M www
yum -y install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl zlib tcl readline-devel glic libxslt-devel gd-devel GeoIP-devel libevent libevent-devel

2.安裝依賴(lài)插件

cd /soft/package/src

openresty安裝包

wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
tar -xf openresty-1.11.2.2.tar.gz

libdrizzle模塊

wget http://openresty.org/download/drizzle7-2011.07.21.tar.gz
tar xzvf drizzle7-2011.07.21.tar.gz
cd drizzle7-2011.07.21/
./configure --without-server
make libdrizzle-1.0
make install-libdrizzle-1.0

openssl依賴(lài)包安裝

wget https://www.openssl.org/source/openssl-1.0.2d.tar.gz
tar -xf openssl-1.0.2d.tar.gz

pcre依賴(lài)

wget -O pcre-8.37.tar.gz \
http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz/download
tar -xf pcre-8.37.tar.gz
wget ftp://91.193.69.2/distributive/FreeBSD/ports/local-distfiles/osa/nginx-accessk
ey-2.0.3.tar.gz
tar xf nginx-accesskey-2.0.3.tar.gz
mv nginx-accesskey-2.0.3 ngx_3rd/nginx-accesskey-master
cd /soft/package/src/ngx_3rd
wget -O ngx_http_consistent_hash.zip https://codeload.github.com/replay/ngx_http_consistent_hash/zip/master
unzip ngx_http_consistent_hash.zip
wget -O nginx-static-etags.zip https://codeload.github.com/mikewest/nginx-static-etags/zip/master
unzip nginx-static-etags.zi wget -O nginx-http-footer-filter.zip https://codeload.github.com/alibaba/nginx-http-footer-filter/zip/master
unzip nginx-http-footer-filter.zip
wget -O form-input-nginx-module.zip https://codeload.github.com/calio/form-input-nginx-module/zip/master
unzip form-input-nginx-module.zip
wget -O ngx_http_accounting_module.zip https://codeload.github.com/Lax/ngx_http_accounting_module/zip/master
unzip ngx_http_accounting_module.zip
wget -O ngx_log_if.zip https://codeload.github.com/cfsego/ngx_log_if/zip/master
unzip ngx_log_if.zip
wget -O nginx-limit-upstream.zip https://codeload.github.com/cfsego/nginx-limit-upstream/zip/master
unzip nginx-limit-upstream.zip
wget -O limit_upload_rate.zip https://codeload.github.com/cfsego/limit_upload_rate/zip/master
unzip limit_upload_rate.zip
wget -O ngx_devel_kit.zip https://codeload.github.com/simpl/ngx_devel_kit/zip/master
unzip ngx_devel_kit.zip
wget -O nginx-module-vts.zip https://codeload.github.com/vozlt/nginx-module-vts/zip/master
unzip nginx-module-vts.zip
wget -O nginx_tcp_proxy_module.zip https://codeload.github.com/yaoweibin/nginx_tcp_proxy_module/zip/master
unzip nginx_tcp_proxy_module.zip
wget -O nginx-module-sts.zip https://codeload.github.com/vozlt/nginx-module-sts/zip/master
unzip nginx-module-sts.zip
wget -O nginx-http-concat.zip https://codeload.github.com/alibaba/nginx-http-concat/zip/master
unzip nginx-http-concat.zip
wget -O nginx-url.zip https://codeload.github.com/vozlt/nginx-module-url/zip/master
unzip nginx-url.zip
wget -O nginx-access-plus.zip https://codeload.github.com/nginx-clojure/nginx-access-plus/zip/master
unzip nginx-access-plus.zip

3.編譯openresty

cd /soft/package/src/ngx_openresty-1.11.2.2
./configure \
--user=www \
--group=www \
--prefix=/soft/openresty-1.11 \
--pid-path=/soft/openresty-1.11/nginx/pid \
--error-log-path=/soft/log/nginx/error.log \
--http-log-path=/soft/log/nginx/access.log \
--http-proxy-temp-path=/soft/openresty-1.11/nginx/proxy_temp \
--http-fastcgi-temp-path=/soft/openresty-1.11/nginx/fastcgi_temp \
--http-client-body-temp-path=/soft/openresty-1.11/nginx/client_body_temp \
--with-openssl=/soft/package/src/openssl-1.0.2d \
--with-pcre=/soft/package/src/pcre-8.37 \
--with-libdrizzle=/usr/local \
--with-threads \
--with-file-aio \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_xslt_module \
--with-http_iconv_module \
--with-http_geoip_module \
--with-http_realip_module \
--with-http_gunzip_module \
--with-http_drizzle_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_image_filter_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--with-mail \
--with-mail_ssl_module \
--add-module=/soft/package/src/ngx_3rd/nginx-accesskey-master/ \
--add-module=/soft/package/src/ngx_3rd/ngx_http_consistent_hash-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-static-etags-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-http-footer-filter-master/ \
--add-module=/soft/package/src/ngx_3rd/ngx_http_accounting_module-master/ \
--add-module=/soft/package/src/ngx_3rd/ngx_log_if-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-http-concat-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-module-vts-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-module-url-master/ \
--add-module=/soft/package/src/ngx_3rd/nginx-access-plus-master/src/c/
gmake && gmake install && ln -s /soft/openresty-1.11 /soft/openresty
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末除秀,一起剝皮案震驚了整個(gè)濱河市糯累,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌册踩,老刑警劉巖泳姐,帶你破解...
    沈念sama閱讀 219,589評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異暂吉,居然都是意外死亡胖秒,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門(mén)慕的,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)阎肝,“玉大人,你說(shuō)我怎么就攤上這事肮街》缣猓” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,933評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵低散,是天一觀(guān)的道長(zhǎng)。 經(jīng)常有香客問(wèn)我骡楼,道長(zhǎng)熔号,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,976評(píng)論 1 295
  • 正文 為了忘掉前任鸟整,我火速辦了婚禮引镊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己弟头,他們只是感情好吩抓,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,999評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著赴恨,像睡著了一般疹娶。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上伦连,一...
    開(kāi)封第一講書(shū)人閱讀 51,775評(píng)論 1 307
  • 那天雨饺,我揣著相機(jī)與錄音,去河邊找鬼惑淳。 笑死额港,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的歧焦。 我是一名探鬼主播移斩,決...
    沈念sama閱讀 40,474評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼绢馍!你這毒婦竟也來(lái)了向瓷?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,359評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤痕貌,失蹤者是張志新(化名)和其女友劉穎风罩,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體舵稠,經(jīng)...
    沈念sama閱讀 45,854評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡超升,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,007評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了哺徊。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片室琢。...
    茶點(diǎn)故事閱讀 40,146評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖落追,靈堂內(nèi)的尸體忽然破棺而出盈滴,到底是詐尸還是另有隱情,我是刑警寧澤轿钠,帶...
    沈念sama閱讀 35,826評(píng)論 5 346
  • 正文 年R本政府宣布巢钓,位于F島的核電站,受9級(jí)特大地震影響疗垛,放射性物質(zhì)發(fā)生泄漏症汹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,484評(píng)論 3 331
  • 文/蒙蒙 一贷腕、第九天 我趴在偏房一處隱蔽的房頂上張望背镇。 院中可真熱鬧咬展,春花似錦、人聲如沸瞒斩。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,029評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)胸囱。三九已至祷舀,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間旺矾,已是汗流浹背蔑鹦。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,153評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留箕宙,地道東北人嚎朽。 一個(gè)月前我還...
    沈念sama閱讀 48,420評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像柬帕,于是被迫代替她去往敵國(guó)和親哟忍。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,107評(píng)論 2 356