nginx作為web伺服器的功能模組

2021-09-25 14:37:42 字數 3497 閱讀 7765

1、nginx虛擬主機

2、https的實現

需要編譯ssl模組

cd nginx-1.17.1/

yum install -y openssl-devel # 編譯ssl模組需要的依賴包

make cert.pem # 製作證書

cp cert.pem /usr/local/nginx/conf/ # 證書在 /usr/local/nginx/conf/才會生效

cd /usr/local/nginx/conf/

vim nginx.conf

server

}server

}

3、重定向

[root@server1 sbin]# vim nginx.conf

server

[root@server1 sbin]# nginx -t

[root@server1 sbin]# nginx -s reload

4、併發、速率限制

[root@server1 conf]# vim nginx.conf

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

允許訪問html/download/的內容

location /download/

[root@server1 conf]# nginx -s reload

客戶端測試:一次併發請求10個,我們設定的併發量是1,因此只會成功1個

5、訪問控制

[root@server1 admin]# pwd

/usr/local/lnmp/nginx/html/admin

[root@server1 admin]# vim index.html

admin page

location /admin/

6、快取設定

7、防止惡意網域名稱解析

[root@server1 conf]# vim nginx.conf

server

[root@server1 www1]# ls images/ //server1的/www1/images下有一張

iso7.gif

server2的預設發布目錄下有乙個假的資源

[root@server2 html]# cat index.html 

//server2將其預設發布頁設為server1主機上的

所以客戶訪問server2的該資源時實際上訪問的是server1上的資源

2)、server1防盜煉

[root@server1 conf]# vim nginx.conf

server

}

這樣配置,再遇到盜鏈的時候直接報403

3)、我們不僅可以在其盜鏈時直接拒絕,還可以做個重定向,在遇到這個的時候,讓盜鏈者訪問我們指定的資源

}9、文字壓縮

(1)、配置

vim conf/nginx.conf

33 gzip on; //開啟gzip壓縮

34 gzip_min_length 20; //設定將被gzip壓縮的響應的最小長度(k)

35 gzip_comp_level 3; //設定響應的gzip壓縮級別(1--9)

(2)、測試

開啟瀏覽器,清空快取(ctrl + shift + delete)

訪問nginx伺服器(172.25.60.1)

curl檢視:ctrl+shift+c--->network--->reload--->看size和transf

10、壓縮

需要重新編譯,匯入第三方模組

load_module modules/ngx_http_image_filter_module.so; //匯入模組

gzip on;

location /download/

nginx -s reload

nginx 作為 gitweb 的伺服器

color 345286 最近在研習 git,並使用 gitolite 來架設 git 服務。同時又想在瀏覽器中能夠以唯讀的方式檢視有哪些版本庫。於是就想到用 gitweb,可是 gitweb 是用 cgi 指令碼寫的,相對於 apache,我更熟悉並喜歡用 ngingx。color color 3...

Web伺服器 Nginx搭建

nginx 輕量級的軟體,併發量遠高與apache httpd tengine 網基於nginx開發的web伺服器專案.gcc pcre devel openssl devel三個固定包 新建普通使用者,以普通使用者的身份執行nginx,避免安全隱患 suid 命令 增大許可權 root nginx...

web伺服器nginx筆記

配置檔案目錄 ubuntu etc nginx nginx.conf配置檔案注釋 nginx使用者及組 使用者 組 user www data 工作程序 數目。根據硬體調整,通常等於cpu數量或者2倍於cpu。worker processes 1 pid 程序識別符號 存放路徑。pid run ng...