lnmp 配置nginx 实现内网/本地域名

需求:微服务 客户端服务器 需要内网访问 api接口服务器
解释:传统的外部网址(比如二级域名)也能实现,但是不安全,于是采用内网域名的形式

实现步骤:
1、nginx解析域名 _innerapi.sd.cn 到 127.0.0.1

$ find / -name hosts
=================
/etc/hosts #这是hosts文件所在的目录
=================
$ vi /etc/hosts

在hosts文件最后一行添加
127.0.0.1 _innerapi.sd.cn
按 ESC
输入 :wq
保存退出
2、添加虚拟主机配置

$ cd /usr/local/nginx/conf/vhost
$ vi _innerapi.sd.cn.conf

输入:

server
    {
        listen 80;
       
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/api.sd.cn;

        include rewrite/thinkphp.conf;
        error_page   404   /404.html;

        include enable-php-pathinfo.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

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

        location ~ /.well-known {
            allow all;
        }
        location ~ /\.
        {
            deny all;
        }
        location ~ \.php(.*)$  {
                fastcgi_pass   127.0.0.1:8080;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
                }
        access_log  /home/wwwlogs/_innerapi.squaredental.cn.log;
    }

pw: 因为项目是thinkphp5,所以有中间的额外加载项,可以去掉
保存退出,重启nginx:

$ lnmp nginx restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值