linux下nginx安装

来源:互联网 发布:阿里云服务器如何续费 编辑:程序博客网 时间:2024/04/29 01:40

配置https时打开openssl

需要三个依赖库:

cd /root/tools/openssl-1.0.0a./configuremake && make installcd /root/tools/zlib-1.2.3./configuremake && make installcd /root/tools/pcre-8.33./configuremake && make install./configure --prefix=/root/tools/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/root/tools/openssl-1.0.0a --with-http_gzip_static_module  --with-http_stub_status_module --with-zlib=/root/tools/zlib-1.2.3 --with-pcre=/root/tools/pcre-8.33



使用nginx搭建https服务器

最近在研究nginx,整好遇到一个需求就是希望服务器与客户端之间传输内容是加密的,防止中间监听泄露信息,但是去证书服务商那边申请证书又不合算,因为访问服务器的都是内部人士,所以自己给自己颁发证书,忽略掉浏览器的不信任警报即可。下面是颁发证书和配置过程。

首先确保机器上安装了openssl和openssl-devel

#yum install openssl#yum install openssl-devel

然后就是自己颁发证书给自己

#cd /usr/local/nginx/conf#openssl genrsa -des3 -out server.key 1024#openssl req -new -key server.key -out server.csr#openssl rsa -in server.key -out server_nopwd.key#openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt



证书生成

https://www.trustasia.com/tools/csr-generate/



参考如下:

nginx+openssl安装

nginx下载 http://www.nginx.org/en/download.html 版本:0.7.65

openssl下载: http://www.openssl.org/source/   版本:1.0.0

 

1.注意:OPENSSL不需要安装,只需要解压出来就行。不然在编译时会提示类似以下的错误:

make[1]: Entering directory `/root/nginx-0.7.65'
cd /server/openssl \
        && make clean \
        && ./config --prefix=/server/openssl/openssl no-shared  no-threads \
        && make \
        && make install
make[2]: Entering directory `/server/openssl'
make[2]: *** No rule to make target `clean'.  Stop.
make[2]: Leaving directory `/server/openssl'
make[1]: *** [/server/openssl/openssl/include/openssl/ssl.h] Error 2
make[1]: Leaving directory `/root/nginx-0.7.65'
make: *** [build] Error 2

 

2.安装Nginx的时候,把openssl路径指定到解压出来的路径:

./configure  --with-http_stub_status_module --with-http_ssl_module --with-openssl=/root/openssl-1.0.0 --with-http_gzip_static_module  --with-http_stub_status_module

之后是一个漫长的等待时间

 

3、生成RSA密钥的方法

openssl genrsa -des3 -out privkey.pem 2048
这个命令会生成一个2048位的密钥,同时有一个des3方法加密的密码,如果你不想要每次都输入密码,可以改成:
openssl genrsa -out privkey.pem 2048
建议用2048位密钥,少于此可能会不安全或很快将不安全。

4、生成一个证书请求
openssl req -new -key privkey.pem -out cert.csr
这个命令将会生成一个证书请求,当然,用到了前面生成的密钥privkey.pem文件
这里将生成一个新的文件cert.csr,即一个证书请求文件,你可以拿着这个文件去数字证书颁发机构(即CA)申请一个数字证书。CA会给你一个新的文件cacert.pem,那才是你的数字证书。

如果是自己做测试,那么证书的申请机构和颁发机构都是自己。就可以用下面这个命令来生成证书:
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
这个命令将用上面生成的密钥privkey.pem生成一个数字证书cacert.pem

5.Nginx配置中,需要修改的地方:

server {
        listen       443;
        server_name  localhost;

        ssl                  on;
    ssl_certificate /usr/local/nginx/conf/cacert.pem;
    ssl_certificate_key /usr/local/nginx/conf/privkey.pem;
    server_name 192.168.10.70
ssl_session_timeout  5m;
}

6.在iptables中打开ssl使用到的443端口,重启iptables.

7.测试。访问时,发现有提示需要证书,应该成功了。


0 0
原创粉丝点击