LNMP下配置域名

一、去域名服务商解析域名到服务器ip

二、进入服务器nginx配置目录

如一个服务器要运行多个项目,可在nginx.conf文件同一级目录下扩展多域名配置:

例:创建vhost目录,vhost目录下根据域名数创建域名配置。

例:域名(mask.test.com)可创建mask.conf,配置内容可网上搜索,很多案例,这里说明几个重要点:

代码段中有##前缀的是需要替换自己的配置的

1、https协议,证书的配置;

端口:443

证书路径配置(例)

server
    {
        listen 443 ssl;
        #listen [::]:80;
        server_name ##your_hostname;
        #ssl on;
        index index.html index.htm index.php default.html default.htm default.php;
        root  ##your_project_path;

        ssl_certificate   ##your_cert_path;
        ssl_certificate_key  ##your_key_path;
        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;

        #include other.conf;
        #error_page   404   /404.html;

        location / {
            if (!-e $request_filename) {
                rewrite  ^/api/(.*)$  /api.php/$1  last;
                rewrite  ^/(.*)$  /index.php/$1  last;
                break;
            }
        }

        include enable-php-pathinfo.conf;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ .*\.(txt)?$
        {
            expires      12h;
        }


        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/xx.log;
    }

2、http强制跳转https;

server
    {
        listen 80;
        #listen [::]:80;
        server_name ##your_hostname;
        index index.html index.htm index.php default.html default.htm default.php;
        root  ##your_project_path;

        return 301 https://$server_name$request_uri;
    }

3、域名配置完后需要在nginx.conf文件最后(http配置大括号里面)include子配置。

include vhost/*.conf

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值