天天看點

Centos7.5 下Nginx配置SSL支援https通路。

核心配置:

• 通過指定由受信任的證書頒發機構(CA)頒發的有效證書,将伺服器配置為偵聽端口上的HTTPS流量。

• 通過配置nginx.conf檔案來加強安全性。示例包括選擇更強大的密碼,并将所有流量通過HTTP重定向到HTTPS。

• 添加HTTP Strict-Transport-Security(HSTS)頭部確定用戶端所做的所有後續請求僅通過HTTPS。

#################################################################################

nginx配置ssl,需要確定nginx包含相應的子產品--with-http_ssl_module

檢視nginx安裝參數是否已經包含此子產品,如果未包含請先安裝此子產品。

[root@linux-node1 ~]# nginx -V

添加/etc/nginx/proxy.conf配置檔案:

[root@linux-node1 ~]# vi etc/nginx/proxy.conf

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffers 32 4k;

編輯/etc/nginx/nginx.conf配置檔案。配置主要包含兩個部分http和server。

vi /etc/nginx/nginx.conf

http {

include /etc/nginx/proxy.conf;

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

server_tokens off;

}

有幾處需要更改

• server_name改成你的域名=申請證書綁定的域名。

• ssl_certificate改成你的公鑰路徑。

• ssl_certificate_key改成你的私鑰路徑。

一些安全配置

防止Clickjacking(點選劫持),Clickjacking是一種惡意技術來收集受感染的使用者的點選。劫持受害者(通路者)點選感染的網站,使用X-FRAME-OPTIONS。

編輯nginx.conf檔案:

[root@linux-node1 ~]# vi /etc/nginx/nginx.conf

将配置中的

add_header X-Frame-Options DENY;

更改為

add_header X-Frame-Options SAMEORIGIN;

重新加載nginx

[root@linux-node1 ~]# service nginx reload

MIME類型的嗅探,此标頭防止大多數浏覽器從聲明的内容類型中嗅探響應,因為标頭訓示浏覽器不要覆寫響應内容類型,使用nosniff選項

添加行

add_header X-Content-Type-Options nosniff;

上文的nginx.conf已配置好此标頭,儲存檔案,重新啟動Nginx。

繼續閱讀