【Linux】虚拟机内部域名解析

为解决无法访问虚拟机public下的文件

  1. 方法一:绑定域名
cd /usr/local/nginx/conf/vhost/   
vi fine-server.conf   // 没有则新建
server {

    listen 80;
    server_name img.fine.dev.cn;// 域名
    root /data/webroot/fine-server/public;  // 项目路径,指定到public下
    index   index.php index.html index.htm;
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})")
    {
        set $curyear $1;
        set $curmonth $2;
        set $curday $3;
        set $curhour $4;
        set $curminutes $5;
        set $curseconds $6;
    }
    access_log /data/logs/nginx/shixuefu/www$curyear$curmonth$curday.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        access_log off;
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        access_log off;
        expires      12h;
    }
}
nginx -t // 检查nginx是否报错
systemctl restart nginx // 重启nginx
vi /etc/hosts
127.0.0.1 img.fine.dev.cn

本地hosts再绑定域名
总结:
在这里插入图片描述

  1. 方法二:绑定ip(推荐)
cd /usr/local/nginx/conf/vhost/   
vi fine-server.conf   // 没有则新建
server {

    listen 80;// 自定义
    server_name 192.168.62.128;// IP
    root /data/webroot/fine-server/public;  // 项目路径,指定到public下
    index   index.php index.html index.htm;
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})")
    {
        set $curyear $1;
        set $curmonth $2;
        set $curday $3;
        set $curhour $4;
        set $curminutes $5;
        set $curseconds $6;
    }
    access_log /data/logs/nginx/fine_server_img_$curyear$curmonth$curday.log;// log名称

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        access_log off;
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        access_log off;
        expires      12h;
    }
}
nginx -t // 检查nginx是否报错
systemctl restart nginx // 重启nginx
// 开放端口号
systemctl start firewalld 
firewall-cmd --zone=public --add-port=80/tcp --permanent 
firewall-cmd --reload 
systemctl stop firewalld 

小知识点

ESC下跳转到最后一行:G
跳转到最后一行并进入Insert模式:O

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值