Nginx 配置一級和二級證書以及作為靜態(tài)資源服務器
Docker 啟動 nginx 容器
version: '3'
services:
root-nginx:
restart: always
container_name: root-nginx
image: nginx:latest
ports:
- 443:443
volumes:
- /path/ssl:/etc/nginx/conf.d/ssl
- ./conf.d/default.conf:/etc/nginx/conf.d/default.conf
卷掛載中的 ssl 證書替換為自己 ssl 證書的位置。
關于 nginx *.conf 配置文件不過多描述!
配置一級證書
server{
listen 443 ssl;
server_name test.com;
charset utf-8;
http2 on;
ssl_certificate /etc/nginx/conf.d/ssl/ssl.pem;
ssl_certificate_key /etc/nginx/conf.d/ssl/ssl.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
location / {
# 默認 nginx 歡迎頁
root /usr/share/nginx/html;
try_files $uri $uri/ =404;
index index.html index.htm;
# 反向代理配置
# proxy_pass http://172.16.2.17:8010;
}
}
配置二級證書
在同一個 default.conf 文件中寫 server 就可以。文章來源:http://www.zghlxwxcb.cn/news/detail-800027.html
server {
listen 443 ssl;
# 正則切割獲得二級域名前綴
# 這里的 server_name 屬性 必須 要是 *.test.com 格式
server_name ~^(?<sub>.+)\.test\.com$;
http2 on;
ssl_certificate /etc/nginx/conf.d/ssl/ssl.cer;
ssl_certificate_key /etc/nginx/conf.d/ssl/ssl.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
# nginx 歡迎頁
root /usr/share/nginx/html;
try_files $uri $uri/ =404;
index index.html index.htm;
# 根據(jù)前綴匹配不同的代理服務
location / {
if ($sub = "portainer") {
proxy_pass http://172.16.2.17:8004;
}
if ($sub = "cp") {
proxy_pass http://172.16.2.17:8085;
}
if ($sub = "static") {
proxy_pass http://172.16.2.17:8995;
}
if ($sub = "esm") {
proxy_pass http://172.16.2.17:8994;
}
}
}
靜態(tài)資源服務器配置
只作為簡單靜態(tài)資源服務器!文章來源地址http://www.zghlxwxcb.cn/news/detail-800027.html
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
# 服務器中的靜態(tài)資源目錄,如使用 docker 部署時,必須要保證正確的卷掛載,不然 404 !
root /usr/share/nginx/html/static;
# 開啟自動目錄索引
autoindex on;
}
}
到了這里,關于Nginx 配置一級和二級證書以及作為靜態(tài)資源服務器的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!