linux中nginx配置https

6 篇文章 0 订阅
5 篇文章 0 订阅
1.查看nginx安装情况,nginx -V看看是否有装有http_ssl_module模块

 nginx -V:
   nginx version: nginx/1.10.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
一般默认rpm安装都会带有http_ssl_module
2.防火墙开启443端口
3.确保机器上安装了openssl和openssl-devel,可以执行以下命令更新:
 yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
4.创建https证书,我创建在/etc/nginx/目录下,等下好配置时好找
 打开nginx目录:
 cd /etc/nginx/
 
 创建服务器私钥:
 openssl genrsa -des3 -out server.key 1024 #根据提示输入证书口令,记住口令,下面要用
 
 创建签名请求的证书(CSR):
 openssl req -new -key server.key -out server.csr
 #输入上面设置的口令
 #根据提示输入相应的信息
 Country Name (2 letter code) [XX]:cn #国家
 State or Province Name (full name) []:zhejiang #省份
      Locality Name (eg, city) [Default City]:hangzhou #城市
 Organization Name (eg, company) [Default Company Ltd]:osyunwei #公司
 Organizational Unit Name (eg, section) []:sys #部门
      Common Name (eg, your name or your server's hostname) []:osyunwei #主机名称
 ...
 对key进行解密:
 openssl rsa -in server.key -out server_nopassword.key #对key进行解密
 
 标记证书使用上述私钥和CSR:
 openssl x509 -req -days 365 -in server.csr -signkey server_nopassword.key -out server.crt
5.配置nginx
 upstream ad_server {
         server 127.0.0.1 weight=1 max_fails=2;
         keepalive 100;
      }
      server {
        listen 443;
        server_name 192.168.1.15;
        ssl on;
        ssl_certificate /etc/nginx/server.crt;
        ssl_certificate_key /etc/nginx/server_nopassword.key;
        location /{
proxy_pass http://ad_server;
                proxy_connect_timeout 900;
                proxy_send_timeout 900;
                proxy_read_timeout 900;
        }
 }
 重启nginx就可以用https://192.168.1.15访问nginx了
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值