CentOS Nginx (1.16.1) https

非YUM源安装Nginx,便于配置https

1 下载Nginx: http://nginx.org/en/download.html,将*.tar.gz上传到CentOS服务器,或者通过如下方式获取

wget https://nginx.org/download/nginx-1.16.1.tar.gz

 

2. 解压并安装

解压:
tar zxvf nginx-1.16.1.tar.gz
配置安装路径及https支持:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
开始安装:
make && make install

 

3. 配置nginx.conf,文件路径位于 /usr/local/nginx/conf/,放开如下代码并修改对应文件位置。

    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      /xxx/xxxx.crt;
        ssl_certificate_key  /xxx/xxxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   /xxx/xxx;
            index  index.html index.htm;
     }
    }

4. 如果需要默认80端口跳转443,即http跳转至https,在nginx.conf代码段server 监听80内添加:

rewrite ^(.*)$ https://$host$1 permanent;

 

5. 启动nginx

启动:
/usr/local/nginx/sbin/nginx -s start
重启:
/usr/local/nginx/sbin/nginx -s reload
停止:
/usr/local/nginx/sbin/nginx -s stop

 

posted @ 2019-11-01 14:09  DONZ  阅读(2078)  评论(0编辑  收藏  举报