摘要:下面的參數(shù)是根據(jù)需要在壓縮或解壓檔案時(shí)可選的。備注了解過(guò)程省略這里添加了模塊生成文件使用系統(tǒng)庫(kù)沒(méi)有用到庫(kù)使用系統(tǒng)庫(kù)這些路徑是要了解的這是配置文件
資源1: 官網(wǎng): http://nginx.org
資源2: 官方學(xué)習(xí)資源, ????wiki,???? nginx安裝之wiki介紹
資源3: 編譯選項(xiàng)列表
資源4: nginx源碼下載列表,當(dāng)前Stable版本是nginx-1.14.0,
資源5: 官方新手入門
資源6: 內(nèi)置變量大全(重點(diǎn)掌握),????內(nèi)置指令大全(重點(diǎn)掌握),????重定向(重點(diǎn)掌握)????核心功能(重點(diǎn)掌握)
安裝資源: nginx源碼地址(版本1.11.2):http://nginx.org/download/ngi...
安裝資源: echo模塊安裝地址(版本):https://github.com/openresty/...
安裝參考: echo模塊安裝方法
安裝時(shí)間:2018-09-12
一:從源碼安裝nginx和echo-nginx-module模塊(推薦) 01: 準(zhǔn)備nginx和echo-nginx-module模塊源碼nginx版本為1.11.2,echo-nginx-module版本為0.61
vagrant@qianjin:~$ wget http://nginx.org/download/nginx-1.11.2.tar.gz vagrant@qianjin:~$ wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz vagrant@qianjin:~$ ls //查看一下,壓縮包在當(dāng)前目錄下 code Dockerfile nginx-1.11.2.tar.gz v0.61.tar.gz vagrant@qianjin:~$ tar -zxvf nginx-1.11.2.tar.gz vagrant@qianjin:~$ tar -zxvf v0.61.tar.gz02: 安裝
vagrant@qianjin:~$ cd nginx-1.11.2 //到解壓后的nginx目錄中 vagrant@qianjin:~/nginx-1.11.2$ ./configure --prefix=/opt/nginx --add-module=/home/vagrant/echo-nginx-module-0.61 // –prefix為nginx安裝位置,–add-module為需要添加的模塊路徑,這里添加解壓后echo-nginx-module路徑 // 執(zhí)行配置后,目錄下多了 Makefile文件和 objs目錄 vagrant@qianjin:~/nginx-1.11.2$ make -j2 //報(bào)錯(cuò): src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’: src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=] h ^= data[2] << 16; ~~^~~~~~~~~~~~~~~~ src/core/ngx_murmurhash.c:38:5: note: here case 2: ^~~~ src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=] h ^= data[1] << 8; ~~^~~~~~~~~~~~~~~ src/core/ngx_murmurhash.c:40:5: note: here case 1: ^~~~ 原因,是將警告當(dāng)成了錯(cuò)誤處理,打開(kāi)/home/vagrant/nginx-1.11.2/objs/Makefile, CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g (去年-Werror) 再重新make -j2 -Wall 表示打開(kāi)gcc的所有警告 -Werror,它要求gcc將所有的警告當(dāng)成錯(cuò)誤進(jìn)行處理 vagrant@qianjin:~/nginx-1.11.2$ make -j2 vagrant@qianjin:~/nginx-1.11.2$ make install03: 測(cè)試
vagrant@qianjin:~$ sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf // -c 指定配置文件的路徑sudo /opt/nginx/sbin/nginx -h了解更多用法 在瀏覽器中輸入 http://192.168.10.10/,如果出現(xiàn)Welcome to nginx!頁(yè)面表示安裝成功04: 配置 建立鏈接
sudo ln -s /opt/nginx/sbin/nginx /usr/bin/nginx // 建立軟鏈接,/usr/local/bin包含于$PATH當(dāng)中,不需要額外的設(shè)置環(huán)境變量了,可以在任何目錄運(yùn)行nginx命令 // 現(xiàn)在可以sudo nginx啟動(dòng),用sudo nginx -s stop等開(kāi)機(jī)啟動(dòng)
編譯安裝需要自己進(jìn)行設(shè)置方可自動(dòng)啟動(dòng)
# 設(shè)置nginx自啟動(dòng),在/lib/systemd/system/ 目錄下創(chuàng)建一個(gè)服務(wù)文件 vim /lib/systemd/system/nginx.service 內(nèi)容如下: [Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop [Install] WantedBy=multi-user.target 文件說(shuō)明 [Unit]部分 Description:描述服務(wù) After:依賴,當(dāng)依賴的服務(wù)啟動(dòng)之后再啟動(dòng)自定義的服務(wù) [Service]部分 Type=forking是后臺(tái)運(yùn)行的形式 ExecStart為服務(wù)的具體運(yùn)行命令(需要根據(jù)路徑適配) ExecReload為重啟命令(需要根據(jù)路徑適配) ExecStop為停止命令(需要根據(jù)路徑適配) PrivateTmp=True表示給服務(wù)分配獨(dú)立的臨時(shí)空間 注意:?jiǎn)?dòng)、重啟、停止命令全部要求使用絕對(duì)路徑 [Install]部分 服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶 # 設(shè)置了自啟動(dòng)后,任意目錄下執(zhí)行 systemctl enable nginx.service # 啟動(dòng)nginx服務(wù) systemctl start nginx.service # 設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng) systemctl enable nginx.service # 停止開(kāi)機(jī)自動(dòng)啟動(dòng) systemctl disable nginx.service # 查看狀態(tài) systemctl status nginx.service # 重啟服務(wù) systemctl restart nginx.service # 查看所有服務(wù) systemctl list-units --type=service // 我還是比較喜歡用下面的方式 vagrant@qianjin:~$ sudo service nginx stop vagrant@qianjin:~$ sudo service nginx star // 實(shí)際下面敲的代碼少 vagrant@qianjin:~$ sudo nginx #啟動(dòng) vagrant@qianjin:~$ sudo nginx -s stop 停止最簡(jiǎn)單的nginx配置文件(只支持靜態(tài)html)
events{ } http { server { server_name symfony.cc; location / { root /var/www/study/symfony; index index.html index.htm; } } }最簡(jiǎn)單的nginx配置文件(支持靜態(tài)html和php)
前提:在hosts中定義了168.192.10.10 symfony.cc
events{ } http { server { server_name symfony.cc; root /var/www/study/symfony; location / { index index.php index.html index.htm; } location ~ .php$ { # 在/etc/php/7.0/fpm/pool.d/www.conf的listen值與fastcgi_pass的值要相對(duì)應(yīng) # ;listen = /run/php/php7.0-fpm.sock # listen = 127.0.0.1:9000 fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } //適合用來(lái)檢查nginx是否正常,當(dāng)配置出問(wèn)題是,就用此配置,再在這個(gè)基礎(chǔ)上修改,一定要明白的是,nginx只是個(gè)web服務(wù)器,碰到php文件,它也不解析,它交給php-fpm來(lái)處理,php-fpm處理完的數(shù)據(jù)再交給nginx了解工作進(jìn)程worker_process
配置位置在:在最外面
語(yǔ)法: worker_processes 4;
值:默認(rèn)為1,一般設(shè)為cpu數(shù)量x2
說(shuō)明:當(dāng)設(shè)為4時(shí),1個(gè)主進(jìn)程master process,4個(gè)工作進(jìn)程worker process,master process的pid會(huì)動(dòng)態(tài)記錄在/opt/nginx/logs/nginx.pid文件中,其余4個(gè)工作進(jìn)程的pid值是遞加1,如主進(jìn)程的pid為3082,那么別外幾個(gè)工作進(jìn)程的pid分別為3083,3084,3085,3086,主進(jìn)程負(fù)責(zé)監(jiān)控端口,協(xié)調(diào)工作進(jìn)程的工作狀態(tài),分配工作任務(wù);工作進(jìn)程負(fù)責(zé)進(jìn)行任務(wù)處理
vagrant@qianjin:~$ ps -ef|grep nginx root 3082 1 0 03:56 ? 00:00:00 nginx: master process nginx -c /opt/nginx/conf/2018091201.conf nobody 3083 3082 0 03:56 ? 00:00:00 nginx: worker process nobody 3084 3082 0 03:56 ? 00:00:00 nginx: worker process nobody 3085 3082 0 03:56 ? 00:00:00 nginx: worker process nobody 3086 3082 0 03:56 ? 00:00:00 nginx: worker process vagrant 3089 2311 0 03:57 pts/0 00:00:00 grep --color=auto nginx二:測(cè)試echo模塊(重點(diǎn))
作用范圍:location塊和location if說(shuō)句中
例子
events{ } http { server { server_name localhost; root /var/www/study/symfony; location / { index index.php index.html index.htm; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; echo "hello,word"; echo Changsha; echo $document_root; echo_flush; } } }
瀏覽器中輸入http://192.168.10.10/a.php, 網(wǎng)頁(yè)中原來(lái)的內(nèi)容不顯示了,只
hello,word Changsha /var/www/study/symfony
使用多帶帶的location來(lái)放echo語(yǔ)句,不影響網(wǎng)頁(yè)
events{ } http { server { server_name localhost; root /var/www/study/symfony; location / { index index.php index.html index.htm; } location /wang { echo "hello,word"; echo -n Changsha; # -n表示這個(gè)不換行,它緊接在echo后面,其它地方忽略 echo $document_root; echo_flush; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
輸入 http://192.168.10.10/wang就會(huì)...
hello,word Changsha/var/www/study/symfony
例3:
location /chen { echo_duplicate 1 $echo_client_request_headers; echo " "; echo_read_request_body; echo $request_body; }
輸出
GET /chen HTTP/1.1 Host: 192.168.10.10 Connection: keep-alive Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9
備注1: tar參數(shù)說(shuō)明(熟悉的略過(guò))
-c: 建立壓縮檔案
-x:解壓(解壓時(shí)要用到這個(gè))
-t:查看內(nèi)容
-r:向壓縮歸檔文件末尾追加文件
-u:更新原壓縮包中的文件
這5個(gè)是獨(dú)立的命令,壓縮解壓都要用到其中一個(gè),可以和別的命令連用但只能用其中一個(gè)。
下面的參數(shù)是根據(jù)需要在壓縮或解壓檔案時(shí)可選的。
-z:有g(shù)zip屬性的
-j:有bz2屬性的
-Z:有compress屬性的
-v:顯示所有過(guò)程
-O:將文件解開(kāi)到標(biāo)準(zhǔn)輸出
下面的參數(shù)-f是必須的
-f: 使用檔案名字,切記,這個(gè)參數(shù)是最后一個(gè)參數(shù),后面只能接檔案名。
備注2:了解configure過(guò)程
checking for OS + Linux 4.15.0-32-generic x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 7.3.0 (Ubuntu 7.3.0-16ubuntu3) checking for gcc -pipe switch ... found 省略 checking for getaddrinfo() ... found configuring additional modules adding module in /home/vagrant/echo-nginx-module-0.61 //這里添加了 echo模塊 + ngx_http_echo_module was configured checking for PCRE library ... found checking for PCRE JIT support ... found checking for zlib library ... found creating objs/Makefile //生成文件Makefile Configuration summary + using system PCRE library 使用系統(tǒng)PCRE庫(kù) + OpenSSL library is not used 沒(méi)有用到OpenSSL庫(kù) + using system zlib library 使用系統(tǒng)zlib庫(kù) // 這些路徑是要了解的 nginx path prefix: "/opt/nginx" nginx binary file: "/opt/nginx/sbin/nginx" nginx modules path: "/opt/nginx/modules" nginx configuration prefix: "/opt/nginx/conf" nginx configuration file: "/opt/nginx/conf/nginx.conf" 這是配置文件 nginx pid file: "/opt/nginx/logs/nginx.pid" nginx error log file: "/opt/nginx/logs/error.log" nginx http access log file: "/opt/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/30876.html
摘要:下面的參數(shù)是根據(jù)需要在壓縮或解壓檔案時(shí)可選的。備注了解過(guò)程省略這里添加了模塊生成文件使用系統(tǒng)庫(kù)沒(méi)有用到庫(kù)使用系統(tǒng)庫(kù)這些路徑是要了解的這是配置文件 資源1: 官網(wǎng): http://nginx.org資源2: 官方學(xué)習(xí)資源, ????wiki,???? nginx安裝之wiki介紹資源3: 編譯選項(xiàng)列表資源4: nginx源碼下載列表,當(dāng)前Stable版本是nginx-1.14.0,資源5...
摘要:安裝及相關(guān)基礎(chǔ)插件將以下所需要的支持包上傳至服務(wù)器中程序源代碼信息輸出緩存清除負(fù)載均衡模塊將所有的開(kāi)發(fā)包解壓縮到目錄中新建文件目錄用于保存的相關(guān)配置進(jìn)入的源碼目錄編譯與安裝配置編譯相關(guān)編譯項(xiàng) 安裝Nginx及相關(guān)基礎(chǔ)插件 1 . 將以下所需要的支持包上傳至服務(wù)器中 nginx-1.11.3.tar.gz : Nginx程序源代碼 echo-nginx-module-0.59.ta...
摘要:在中,如果使用的方式,這些都已經(jīng)配置好了,默認(rèn)情況下,就是開(kāi)機(jī)自啟動(dòng),使用自啟動(dòng)啟動(dòng)查看狀態(tài)設(shè)置為系統(tǒng)默認(rèn)啟動(dòng) 安裝時(shí)間 2018-10-01 安裝環(huán)境 win10+virtualbox+ubuntu server 16,安裝在虛擬機(jī)ubuntu server中 安裝 下面定義成一句命令,適合在docker 中使用 # 安裝庫(kù) sudo apt-get update && su...
摘要:服務(wù)器架構(gòu)模塊化結(jié)構(gòu)服務(wù)器的開(kāi)發(fā)完全遵循模塊化設(shè)計(jì)思想什么是模塊化開(kāi)發(fā)單一職責(zé)原則,一個(gè)模塊只負(fù)責(zé)一個(gè)功能將程序分解,自頂向下,逐步求精高內(nèi)聚,低耦合的模塊化結(jié)構(gòu)核心模塊最基本最核心的服務(wù),如進(jìn)程管理權(quán)限控制日志記錄標(biāo)準(zhǔn)模塊服務(wù)器的標(biāo)準(zhǔn)功能 Nginx服務(wù)器架構(gòu) 模塊化結(jié)構(gòu) Nginx 服務(wù)器的開(kāi)發(fā)完全遵循模塊化設(shè)計(jì)思想 什么是模塊化開(kāi)發(fā)? 單一職責(zé)原則,一個(gè)模塊只負(fù)責(zé)一個(gè)功能 將程...
閱讀 1421·2021-09-02 09:53
閱讀 2680·2021-07-29 13:50
閱讀 1727·2019-08-30 11:07
閱讀 1586·2019-08-30 11:00
閱讀 1464·2019-08-29 14:00
閱讀 1858·2019-08-29 12:52
閱讀 2578·2019-08-29 11:11
閱讀 3432·2019-08-26 12:23