配置Nginx部署静态资源和自动跳转到https

一、首先在阿里云后台添加域名解析:  

二、两个网站的静态资源在以下目录:

   /www/temp/blog/public

三、在服务器端配置nginx:

  cd /etc/nginx/conf.d 添加两个文件

  以admin-locusy-top.conf为例,添加以下配置(注意图片等资源文件的目录,所在的static目录是在public下的):

server {
  listen 80;
  server_name admin.locusy.top;
  root /www/temp/blog/public/admin;
  index index.html;
  location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$ {
    root /www/temp/blog/public;
    autoindex on;
  }
}

  www-locusy-top.conf 增加了https协议的配置:

server {
        listen 80;
        server_name www.locusy.top;
        root /www/temp/blog/public/client;
        index index.html;
        location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$ {
                root /www/temp/blog/public;
        }
        rewrite ^(.*)$  https://$host$1 permanent;
#       return 301 https://www.locusy.top$request_uri;
}

server {
        listen 443;
        server_name www.locusy.top;
        ssl on;
        ssl_certificate   cert/1652724_www.locusy.top.pem;
        ssl_certificate_key  cert/1652724_www.locusy.top.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        root /www/temp/blog/public/client;
        index index.html;
        location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$ {
                root /www/temp/blog/public;
        }

#       if ($ssl_protocol = "") {
#               rewrite ^(.*) https://$host$1 permanent;
#       }
}

三、重启nginx:

  nginx -s reload

四、打开网页:

  locusy.top

  admin.locusy.top

转载于:https://www.cnblogs.com/angelatian/p/10158468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值