您当前的位置: 首页 >  http

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

nginx配置https

柳鲲鹏 发布时间:2020-06-07 08:06:45 ,浏览量:0

  • 使用openssl生成证书

openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /usr/local/nginx/conf/cert.key -out /usr/local/nginx/conf/cert.crt
  • 编译
# need openssl, pcre, zlib

./configure \
    --with-http_stub_status_module \
    --with-http_ssl_module
 
make
 
sudo make install
  • 查看版本
/usr/local/nginx/sbin/nginx -V
  • 配置https

nginx.conf

    server {
 
        listen	80;
        server_name localhost;
        rewrite ^(.*) https://$server_name$1 permanent; #http to https
    }
server {
    listen 443 ssl;
    server_name localhost;
    ssl_certificate       /usr/local/nginx/conf/cert.crt;
    ssl_certificate_key   /usr/local/nginx/conf/cert.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    server_tokens off;

    fastcgi_param   HTTPS               on;
    fastcgi_param   HTTP_SCHEME         https;
    access_log /usr/local/nginx/logs/httpsaccess.log;
}
  • 检查配置
sudo /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  • 启动
/usr/local/nginx/sbin/nginx -s reload
  • 访问

 

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0520s