如何配置NGINX反向代理并加密证书

时间:2018-07-15 18:46:20

标签: nginx reverse-proxy lets-encrypt

我已经将Nginx服务器设置为Python / WSGI Web应用程序的反向代理。这是启用站点的配置文件:

server {
    listen 80;
    server_name mydomain.com;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        include     uwsgi_params;
        uwsgi_pass  unix:/home/user/webapp/webapp.sock;
    }

我可以使用certbot进行安装,在该安装中Nginx不是反向代理,它像一个魅力一样工作,但是在上述配置中,当我运行certbot时,出现以下错误:"Could not automatically find a matching server block for mydomain.com. Set the server_name {{1 }}。根据{{​​3}},它看起来像是Nginx的错误配置。我基于此1创建了证书,但是我不知道如何配置nginx使其使用作为反向代理的新证书来接受https。

1 个答案:

答案 0 :(得分:0)

此配置对我有用:

server {
    listen 80 default_server;

    listen 443 ssl;
    server_name mydomain.com www.mydomain.com;

    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

    ssl_stapling on;
    ssl_stapling_verify on;

    access_log /var/log/nginx/nginxSSL.log combined;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        include     uwsgi_params;
        uwsgi_pass  unix:/home/user/webapp/webapp.sock;
    }
}