nginx + PHP 下 https的设置。

来源:互联网 发布:python做搜索引擎 编辑:程序博客网 时间:2024/06/08 22:29
1.   创建key

openssl genrsa -des3 -out server.key 2048

输入密码即可。

2.  创建 csr 

openssl req -new -key engir.key -out server.csr

按流程填写,如

Country Name (2 letter code) [GB]: JP
State or Province Name (full name) [Berkshire]:Tokyo
Locality Name (eg, city) [Newbury]:Bunkyo-ku
Organization Name (eg, company) [My Company Ltd]: HuaWei
Organizational Unit Name (eg, section) :ENGR
Common Name (eg, your name or your server's hostname) []:abc.com
Email Address []:info@it.co.jp    注意邮件地址要和注册域名时的邮件地址一样


Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:  回车
An optional company name []:  回车

3. 通过  server.key   server.csr  在相应的网站申请 证书

如: http://www.startssl.com/

http://ocsp.godaddy.com/

申请成功后会得到两个文件:

gd_bundle.crt   abc.com.crt

4.  设置nginx的配置

上传 gd_bundle.crt   abc.com.crt 文件至 nginx的配置目录下   /usr/local/nginx/conf

执行

cat abc.com.crt gd_bundle.crt > abc.com.chained.crt

Nginx的配置如下:

    server {
        listen       443;
        server_name  ttt.e.com;


        ssl                  on;
        ssl_certificate      /usr/local/nginx/conf/abc.com.chained.crt;
        ssl_certificate_key  /usr/local/nginx/conf/abc.com.key;
        ssl_protocols        SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers          HIGH:!aNULL:!MD5;

        location / {
            root   html;
            index  index.php;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
      fastcgi_param HTTPS on;
            include fastcgi.conf;
        }
    }

5.  验证

执行 

openssl s_client -connect www.godaddy.com:443

最后访问  https://abc.com  如果能看到证书的信息,而且连接都正常就OK了。


注意:

安装nginx 时要加上https模块,编译时:


./configure --with-http_sub_module --with-http_ssl_module 


可以用  /usr/local/nginx/sbin/nginx -V  来查看。


设置完密码后,重启nginx需要输入密码,想让不用输入密码 执行  openssl rsa -in server.key -out server.key


一个nginx 上只能放一个https 的服务,否则会出错。


原创粉丝点击