nginx简单的SSL连接

时间:2014-08-05 09:12:30

标签: ssl nginx

我是使用nginx设置简单SSL连接的新手。我在下面编写的代码是可访问的,但它不是使用SSL运行的。我错过了什么?

我的测试网站只是一个简单的index.html。我的证书和密钥保存在/etc/ssl/certs

 server {
     listen 80;
     server_name             example.com;

     location / {
         proxy_pass https://example.com:443;
     }
 }

 server {
     listen 443;
     root                    /home/deploy/test;

     ssl on;
     ssl_certificate      /etc/ssl/certs/server.crt;
     ssl_certificate_key  /etc/ssl/certs/server.key;
 }

1 个答案:

答案 0 :(得分:0)

您必须将非HTTPS重定向到HTTPS,而不是代理传递。

server {
  listen 80;
  server_name example.com;
  return 301 https://example.com$request_uri;
}
server {
  listen 443;
  server_name example.com;
  root                    /home/deploy/test;

  ssl on;
  ssl_certificate      /etc/ssl/certs/server.crt;
  ssl_certificate_key  /etc/ssl/certs/server.key;
}