最初,我在两个不同的端口上为两个服务(Radicale 和 LMS)配置了 NGINX。我在/etc/nginx/nginx.conf
. 对互联网的访问MYDOMAIN:8000
和访问将分别重定向到:8009
和。3001
Radicale
LMS
我在服务器上设置了证书来启用它,然后运行sudo certbot --nginx -d MYDOMAIN
生成letsencrypt证书。之后我禁用了我自己的证书(我只需要设置它们以使配置文件无错误)。
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
keepalive_timeout 65;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
# reduce logging
access_log off;
# access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
# include /etc/nginx/conf.d/*.conf;
# include /etc/nginx/sites-enabled/*;
auth_basic "NGINX";
auth_basic_user_file /etc/nginx/.htpasswd;
# old, before Certbot
# ssl_certificate ssl/server.crt;
# ssl_certificate_key ssl/server.key;
server {
server_name MYDOMAIN;
listen 8000 ssl;
location / {
proxy_pass http://localhost:8000;
proxy_set_header X-Script-Name /;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Remote-User $remote_user;
proxy_set_header Host $http_host;
proxy_pass_header Authorization;
auth_basic "Nginx-Radicale - Password required";
}
# generated with: sudo certbot --nginx -d MYDOMAIN
ssl_certificate /etc/letsencrypt/live/MYDOMAIN/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/MYDOMAIN/privkey.pem; # managed by Certbot
}
server {
server_name MYDOMAIN;
listen 8009;
return 301 https://MYDOMAIN:3001;
}
server {
server_name MYDOMAIN;
listen 3001;
location / {
proxy_pass http://localhost:3000/;
auth_basic "NGINX";
}
}
}
现在我更改了我的设置,并希望将server
配置的一部分拆分到nginx/conf.d
子目录中以进行干净的设置。我想让原件原封不动地nginx.conf
调整我自己的两个文件:
pi@RPi64:/etc/nginx $ cat conf.d/radicale.conf
server {
server_name MYDOMAIN;
listen 8000;
# ssl;
location / {
proxy_pass http://localhost:5232;
proxy_set_header X-Script-Name /;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Remote-User $remote_user;
proxy_set_header Host $http_host;
proxy_pass_header Authorization;
auth_basic "Nginx-Radicale - Password required";
}
}
第二个文件:
pi@RPi64:/etc/nginx $ cat conf.d/LMS.conf
server {
server_name MYDOMAIN;
listen 8009;
return 301 https://MYDOMAIN:3001;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/MYDMOAIN/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/MYDOMAIN/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name MYDOMAIN;
listen 3001;
location / {
proxy_pass http://localhost:3000/;
auth_basic "NGINX";
}
}
如您所见,我注释掉了ssl
第一个文件中的部分。如果我让它进来sudo nginx -t
,就会给出缺少证书的错误。我想避免必须设置自己的证书。
此外,您可以看到运行certbot
在我的第二个文件中添加了五行:
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/MYDMOAIN/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/MYDOMAIN/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
我认为 certbothttps
在这个文件中找到了,然后决定在那里添加证书。
但是,我想为整个服务器添加证书——这意味着两个站点/文件。
特别是由于更新证书的过程必须定期进行,我想确保不涉及手动复制。
如何告诉Certbot
为两个文件插入证书?我是否必须先添加自己的证书才能让 certbot 识别请求?
nginx.conf
或者将证书添加到主文件是否有意义?难道我做错了什么?