加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx ssl的安装和配置

发布时间:2020-12-13 21:42:03 所属栏目:Nginx 来源:网络整理
导读:前段时间搞了一下apache的ssl,今天有时间把nginx的也搞了一下。关于证书的生成在这儿就不多说了了,请参考前面写过的 openssl建立证书,非常详细配置ssl+apache ,本文用的证书就是前段时间用openssl生成的。 一,安装nginx 如果你已经安装过nginx的话,看

前段时间搞了一下apache的ssl,今天有时间把nginx的也搞了一下。关于证书的生成在这儿就不多说了了,请参考前面写过的openssl建立证书,非常详细配置ssl+apache,本文用的证书就是前段时间用openssl生成的。

一,安装nginx

如果你已经安装过nginx的话,看一下你安装的时候,有没有安装ssl模块(http_ssl_module),有的话说明支持ssl,如果没有呢,就要重新编译一下nginx了,我一直没发现nginx有添加模块的工具,不像apache自带有一个工具apxs,可以添加apache模块,不要重新编译apache。如果有人知道不知,可否告诉我一下,先谢谢了。

[root@BlackGhost sbin]# ./nginx -V
nginx version: nginx/0.8.15
built by gcc 4.4.1 (GCC)
configure arguments: --user=zhangy --group=users --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/zhangy/pcre-7.9

如果没有发现--with-http_ssl_module这个东西的话,加上去,重新编译一下就好了。

二,配置nginx.conf

将在apahce下生成的证书copy到nginx下面

cp -R /usr/local/apache/conf/ssl /usr/local/nginx/conf/

建一个ssl.conf

vi ssl.conf

?ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/server.key;

vi nginx.conf
server
 {
 listen?????? 443;
 server_name? :443;
 index index.html index.htm index.php;
 root? /home/zhangy/www/test;
 include ssl.conf;
 keepalive_timeout?? 60;

location /
 {
 #fastcgi_pass? unix:/tmp/php-cgi.sock;
 fastcgi_pass? 127.0.0.1:9000;
 fastcgi_index index.php;
 include fcgi.conf;
 }

 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires????? 30d;
 }

 log_format? ssltest? '$remote_addr - $remote_user [$time_local] "$request" '
 '$status $body_bytes_sent "$http_referer" '
 '"$http_user_agent" $http_x_forwarded_for';
 access_log? /var/log/ssl.log? ssltest;
 }

到这儿基本上就配置好了。

三,启动nginx和php-cgi,测试ssl

[root@BlackGhost sbin]# /usr/local/nginx/sbin/nginx
Enter PEM pass phrase:

在这里填的密码是服务器证书的密码

nginx ssl

nginx ssl

四,参考文档

nginx在线中文手册:http://blog.51yip.com/manual/nginx/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读