1. Erstellung des Zertifikats
Sie können auf diese Website verweisen, um ein Zertifikat zu erstellen. Rufen Sie die Website auf und geben Sie den Domänennamen ein, um ein Zertifikat zu erstellen
SSL-Zertifikatsgenerierung (lddgo.net) https://www.lddgo.net/encrypt/ssl
2. Laden Sie das Zertifikat in das Zertifikatverzeichnis von Nginx herunter
In diesem Beispiel wird Nginx mit Docker bereitgestellt und die Konfiguration von Nginx Docker erfolgt im Voraus
Nginx, Docker-Compose-Konfiguration
version: "3.1"
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- 8001:8001
- 80:80
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/cert:/etc/nginx/cert
- ./logs/nginx:/var/log/nginx
- ./phpmyadmin:/var/project/phpmyadmin
- ./c-front:/var/project/c_frontend
restart: always
Ändern Sie die Nginx-Konfigurationsdatei
server {
listen 80;
server_name yuming.com;
return 301 https://yuming.com:8001$request_uri;#配置80端口转发到https://yuming.com:8001
}
server{
listen 8001 ssl;
server_name yuming.com;
ssl on;
ssl_certificate /etc/nginx/cert/cert.pem;
ssl_certificate_key /etc/nginx/cert/private.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
error_page 497 301 https://$http_host$request_uri;
charset UTF8;
location / {
root /var/project/c_frontend;
}
location /api {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://192.168.103.206:8002;
}
}
3. Starten Sie Docker Nginx neu
andere:
# HTTP leitet automatisch zu HTTPS
um. ^(.*) https://$server_name$1 permanent;
} #
Web-Download-Konfiguration
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
location /downloads {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
}