Nginx備忘錄

1、查看進程
ps -ef | grep nginx
ps aux | grep nginx(較爲詳細)

2、啓動
/usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf
/opt/application/nginx/sbin/nginx -c /opt/application/nginx/conf/nginx.conf

3、停止
從容關閉:kill -QUIT ID
快速:kill -TERM ID
強制:kill -9 nginx

4、重啓
kill -HUP ID

5、限制IP直接訪問
if ( $host ~* "\d+\.\d+\.\d+\.\d+" ) {
    return 400;
}

6、跨域配置
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

7、流量限制
limit_rate_after 10M;
limit_rate 1M;

8、訪問者地理信息
GeoIP.dat
GeoLiteCity.dat
geoip_country /usr/geoip/GeoIP.dat;
geoip_city /usr/geoip/GeoLiteCity;

9、常用模塊
- Xslt模塊:它是一個過濾器模塊,可以藉助一個或者多個Xslt模塊轉化XML響應
- Expires與ETag:都用於有效控制客戶端緩存
-  X-Sendfile:處理文件下載相關
- WebDAV,Cook:添加--with-http_dav_module,ngx_http_userid_module模塊
- 實現對響應體內容的替換:添加--with_http_sub_module模塊

10、記錄原始客戶端IP(with-http_realip_module)
set_real_ip_from 192.168.1.1/24;(1)
set_real_ip_from 100.100.0.0/16;
real_ip_header X-Real-IP;(3)
(1)代表指定信任的地址,將會被替代爲精確地IP地址
(2)real_ip header [X-Real-IP | X-Forwarded-For]
用於設置使用哪個頭來替換IP地址,如果使用了X-Forwarded-For,那麼該模塊將會使用
X-Forwarded-For頭中的最後一個IP地址來替換前端代理的IP地址

11、負載均衡使用upstream

12、配置SSL需使用openssl和openssl-devel

13、查看工作狀態(with-http_stub_status_module)
stub_status on;
access_log off;

14、控制站點訪問
allow 192.168.1.8 允許訪問
deny 192.168.1.9 禁止訪問

15、反向代理使用proxy_配置
16、壓縮限速使用with-http_gzip_static_module

17、提供FTP下載
autoindex on;
autoindex_exact_size on;
autoindex:
1.啓用或禁止自動,目錄列表
2.有兩個參數:on和off,默認值爲off
autoindex_exact_size:
1.設定目錄列表文件顯示格式,是否已精確的大小顯示
2.有兩個參數:on和off,默認值爲on
3.精確顯示是字節方式顯示 , 取整顯示是使用KB、MB、GB顯示
autoindex_localtime:
1.是否在目錄列表中以本地時間顯示文件時間
2.有兩個參數:on和off,默認值爲off
3.它使用的是GMT時間

18、防止DDos攻擊使用模塊ngx_http_limit_req_module和ngx_http_limit_conn_module
19、限制併發limit_zone、limit_conn
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章