1. 程式人生 > 其它 >志宇-Nginx學習

志宇-Nginx學習

技術標籤:Linux

Nginx

Nginx搭建靜態資源伺服器

1.jpg檔案放到/software/img目錄下
然後訪問https://www.lizhiyu.xyz/img/1.jpg即可下載圖片
配置檔案如下

   location /img {
       alias /software/img/;
   }

Nginx配置https服務

安裝依賴
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel


刪除安裝過的包,然後重新安裝nginx(因為需要安裝ssl模組)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
配置檔案如下

http {
    server {
        listen       80;
        server_name  localhost;

        location / {
			# 配置http 永久重定向到https
            rewrite ^/(.*)  https:
//www.lizhiyu.xyz/$1 permanent; } } # HTTPS server server { # https使用443,記得將開啟埠 listen 443 ssl; # 配置域名 server_name www.lizhiyu.xyz; #證書位置 ssl_certificate /usr/local/https/5148543_www.lizhiyu.xyz.pem; #金鑰位置 ssl_certificate_key /
usr/local/https/5148543_www.lizhiyu.xyz.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } } }

Nginx流量統計

access.log 日誌記錄格式如下
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' $request_time;

檢視訪問最頻繁的前100個IP
awk '{print $1}' access.log | sort -n |uniq -c | sort -rn | head -n 100
統計訪問最多的url 前20名
cat access.log |awk '{print $7}'| sort|uniq -c| sort -rn| head -20 | more
統計耗時介面, 列出傳輸時間超過 2 秒的介面,顯示前5條
cat access.log|awk '($NF > 2){print $7}'|sort -n|uniq -c|sort -nr|head -5
​備註:$NF 表示最後一列, awk ‘{print $NF}’

Nginx黑白名單攔截

OpenResty的學習

\

LVS + KeepLived瞭解