nginx 加固配置

2021-10-04 04:24:36 字數 2817 閱讀 3853

禁止目錄瀏覽

限制目錄執行許可權

錯誤頁面重定向

最佳經驗實踐

限制http請求方法

限制ip訪問

限制併發和速度

控制超時時間

風險操作項

防盜煉補丁更新

適用於使用nginx進行部署的web**。

熟悉nginx配置,能夠nginx進行部署,並能針對站點使用nginx進行安全加固。

1、 根據站點開放埠,程序id,確認站點採用nginx進行部署;

2、 找到nginx安裝目錄,針對具體站點對配置檔案進行修改;

3、 在執行過程中若有任何疑問或建議,應及時反饋。

詳細操作

以下為詳細操作:

備份nginx.conf 配置檔案。

修改配置,按如下設定日誌記錄檔案、記錄內容、記錄格式,新增標籤為main的log_format格式

1.(http標籤內,在所有的server標籤內可以呼叫):

在server標籤內,定義日誌路徑

access_log logs/host.access.log main

儲存,然後後重啟nginx服務。

備份nginx.conf配置檔案。

autoindex off;

儲存,然後後重啟nginx服務。

備份nginx.conf配置檔案。

#示例:去掉單個目錄的php執行許可權

location ~ /attachments/…(php|php5)?$

i#示例:去掉多個目錄的php執行許可權

儲存,然後後重啟nginx服務。

需要注意兩點:

1、以上的配置檔案**需要放到 location ~ .php上面,如果放到下面是無效的;

2、attachments需要寫相對路徑,不能寫絕對路徑。

備份nginx.conf配置檔案。

修改配置,在http{}段加入如下內容

修改內容:

errordocument 400 /custom400.html

errordocument 401 /custom401.html

errordocument 403 /custom403.html

errordocument 404 /custom404.html

errordocument 405 /custom405.html

errordocument 500 /custom500.html

其中401.html、402.html、403.html、404.html、405.html、500.html 為要指定的錯誤提示頁面。

儲存,重啟 nginx 服務生效備份nginx.conf配置檔案。

server_tokens off;

儲存,然後後重啟nginx服務。備份nginx.conf配置檔案。

if (request_method! ~(get∣head∣post)$ )

儲存,然後後重啟nginx服務。

備註:只允許常用的get和post方法,頂多再加乙個head方法

備份nginx.conf配置檔案。

location /

儲存,然後後重啟nginx服務。備份nginx.conf配置檔案。

儲存,然後後重啟nginx服務。備份nginx.conf配置檔案。

儲存,然後後重啟nginx服務。備份nginx.conf配置檔案。

user nobody;

儲存,然後後重啟nginx服務。備份nginx.conf配置檔案。

儲存,然後後重啟nginx服務。軟體資訊

檢視軟體版本 nginx -v

測試配置檔案 nginx –t

補丁安裝

手動安裝補丁或安裝最新版本軟體

Nginx加固 Tomcat加固

二 tomcat加固 nginx禁止顯示版本有兩種方法 vim usr local nginx conf nginx.conf server tokens off src core nginx.h define nginx version 1.9.15 define nginx ver nginx ...

MySQL 作業系統加固配置

應按照使用者分配賬號,避免不同使用者間共享賬號 應刪除或鎖定與資料庫執行 維護等工作無關的賬號 口令授權 日誌補丁 網路連線 可信ip位址訪問控制 連線數設定 命令 mysql u root p 以普通賬戶安全執行mysqld,禁止mysql以管理員賬號許可權執行 操作指南 檢查方法 各種作業系統下...

nginx動態配置配置

nginx中的conf檔案配置測試 upstream backserver server upsync指令指定從consul哪個路徑拉取上游伺服器配置 upsync timeout配置從consul拉取上游伺服器配置的超時時間 upsync interval配置從consul拉取上游伺服器配置的間隔...