美文网首页
Vapor-Nginx配置

Vapor-Nginx配置

作者: 遥遥领先M | 来源:发表于2019-01-25 12:04 被阅读4次

    Nginx安装

    sudo apt-get update
    sudo apt-get install nginx
    

    测试是否安装成功

    浏览器输入你的ip如下图所示


    屏幕快照 2019-01-25 11.48.45.png

    配置代理

    cd /etc/nginx/sites-enabled/
    

    使用vim创建xxx.com的配置文件

    vim xxx.com;//你的域名
    

    填入以下内容,然后按 esc 输入 :wq 按回车

    server {
            server_name xxx.com;//你的域名
            listen 80;// 监听80端口
            try_files $uri @proxy;
            client_max_body_size 20m;
            location @proxy {
                    proxy_pass http://127.0.0.1:8999;// 转发到你本地端口
                    proxy_pass_header Server;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_pass_header Server;
                    proxy_connect_timeout 3s;
                    proxy_read_timeout 10s;
            }
    }
    
    

    申请SSL证书

    在阿里云控制台-产品与服务-安全(云盾)-CA证书服务(数据安全),选择“免费版DV SSL”,点击购买证书


    屏幕快照 2019-01-26 11.12.13.png

    列表中找到已签发的证书,下载:


    屏幕快照 2019-01-26 11.09.56.png

    下载的文件有两个:

    1781133_dakaq.com.pem
    1781133_dakaq.com.key
    

    配置SSL证书

    nginx的安装目录为:/etc/nginx/。进入目录,增加cert/文件夹,把刚刚下载的两个文件上传到cert/文件夹中。

    server {
        ...
    
        listen 443 ssl;
    
        ssl_certificate /cert/1781133_dakaq.com.pem;
        ssl_certificate_key /cert/1781133_dakaq.com.key;
    
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_stapling on;
        ssl_stapling_verify on;
        add_header Strict-Transport-Security max-age=15768000;
    
        ...
    
        location @proxy {
           ...
        }
    }
    

    然后执行

    sudo service nginx restart // 重启
    sudo service nginx reload// 重新加载
    

    Nginx基础命令

    sudo nginx -t //测试配置文件是否正确
    sudo service nginx stop // 停止
    sudo service nginx start // 启动
    sudo service nginx restart // 重启
    sudo service nginx reload// 重新加载
    

    相关文章

      网友评论

          本文标题:Vapor-Nginx配置

          本文链接:https://www.haomeiwen.com/subject/nsjmjqtx.html