我按照 this 文章设置了 2 个 Express.js 网站。我成功部署了网站,我可以将这些内容写入浏览器以获取我想要的不同网站。
http://myIpAdress:8080
http://myIpAdress:9000
我什至将域名连接到 IP 地址,这样我就可以将这些写入我的浏览器以获取不同的网站。我只是隐藏了我的真实域名并假设这些是真实域名。
http://myWebsite.com:8080
http://myWebsite2.com:9000
现在下一步是安装一个 nginx 服务器,我也成功地做到了。我取消了“/etc/nginx/sites-available”下的“默认”文件的链接。我创建了 2 个不同的配置文件,分别命名为“myWebsite.com”和“myWebsite2.com”并将它们链接起来。
下一步是安装 certbot,文章中给出的说明有点过时,因为终端告诉我这种安装 certbot 的方式已被弃用。
我在 here 上找到了如何正确安装 certbot。我遵循了命令,但是当我尝试编写此命令时:
$ sudo certbot certonly --nginx
它抛出如下错误:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /etc/nginx/nginx.conf -t.
nginx: [emerg] open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myWebsite.com:19
nginx: configuration file /etc/nginx/nginx.conf test failed
Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myWebsite.com:19\nnginx: configuration file /etc/nginx/nginx.conf test failed\n')
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myWebsite.com:19\nnginx: configuration file /etc/nginx/nginx.conf test failed\n')
我在这一点上困了好几天......
这是我的配置文件“myWebsite.com”的内容:
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name myWebsite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
listen [::]:443 ssl; #ipv6only=on; # managed by Certbot
# listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myWebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myWebsite.com/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 {
if ($host = myWebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
# listen 80 default_server;
# listen [::]:80 default_server;
server_name myWebsite.com;
return 404; # managed by Certbot
}
感谢您的帮助。