nginx配置|nginx使用GoDaddy ssl证书配置详解

时间:2020-10-02  来源:nginx  阅读:

生成私钥(key)和证书请求文件(csr)

打开终端,输入以下命令

openssl req -new -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr

生成过程会询问几个常见问题,比如City、Country等等。

最后会询问challenge password,输入的时候记住就可以了。

执行完以上命令后,当前目录会多出“domain.key”和“domain.csr”文件

Goddy证书

购买完SSL证书之后会有一个初始化过程,将第1步中的domain.csr文件所有内容填写到“CSR”输入框中,Goddy会检测配置等操作,操作完成之后会签发证书,点击下载即可,下载时服务器类型选择“其他”。

Nginx配置

下载证书的时候压缩包内容类似如下图

QQ图片20160523195944

正常情况下nginx配置SSL需要key和crt文件即可。

这里有两个crt所以需要进行证书合并操作。

打开终端,执行以下命令:

cat 53f58e3ac2172cd5.crt gd_bundle-g2-g1.crt > domain.crt

文件名请根据实际情况进行修改。

证书合并完成,接下来打开Nginx的配置文件,笔者这里证书目录位于“/root/crt”

server
 {
 listen 443;
 #listen [::]:80;
 server_name domain;
 index index.html index.htm index.php default.html default.htm default.php;
 root /home/wwwroot/domain;
 
 location = /favicon.ico {
 log_not_found off;
 access_log off;
 }
 
 location = /robots.txt {
 allow all;
 log_not_found off;
 access_log off;
 }
 location / {
 if (!-e $request_filename) {
 rewrite ^/(.*)$ /index.php?$1 last;
 }
 }
 
 include other.conf;
 #error_page 404 /welcome.html;
 #error_page 500 502 504 = /welcome.html;
 location ~ [^/]\.php(/|$)
 {
 # comment try_files $uri =404; to enable pathinfo
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php-cgi.sock;
 fastcgi_index index.php;
 include fastcgi.conf;
 #include pathinfo.conf;
 }
 
 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires 30d;
 }
 location ~ .*\.(html|htm)?$
 {
 expires 10d;
 }
 location ~ .*\.ttf$
 {
 add_header Access-Control-Allow-Origin *;
 expires 30d;
 }
 location ~ .*\.(js|css)?$
 {
 expires 10d;
 }
 ssl on;
 ssl_certificate /root/crt/domain.crt;
 ssl_certificate_key /root/crt/domain.key;
 access_log off;
 }

保存之后执行 nginx reload 即可。

nginx配置|nginx使用GoDaddy ssl证书配置详解

http://m.bbyears.com/caozuoxitong/102169.html

推荐访问:nginx负载均衡 nginx怎么读
相关阅读 猜你喜欢
本类排行 本类最新