为自己做的项目配置域名(只有自己可以通过此域名访问)

1、配置本机的dns

  • 进入C:\Windows\System32\drivers\etc\hosts进行修改(此为示例域名,需改为自己需要的)
    在这里插入图片描述
127.0.0.1 localhost user.gmall.com cart.gmall.com manage.gmall.com www.gmall.com …
  • 然后打开cmd,输入ipconfig /flushdns进行刷新
    在这里插入图片描述
  • 此时可以直接访问http://user.gmall.com:8080/index,相当于访问了http://localhost:8080/index(访问index是因为我的controller的代码)
  • controller代码如下
   @GetMapping("index")
    public String index(){
        return "hello user";
    }

2、通过nginx去代理端口号

  • 在nginx文件夹找到conf文件夹并进入,打开nginx.conf,在http内加入如下代码
upstream user.gmall.com{
       server 127.0.0.1:8080;
    }
   server {
     listen 80;
     server_name user.gmall.com;
     location / {
        proxy_pass http://user.gmall.com;
        proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
     }
}
  • 然后启动nginx即可通过http://user.gmall.com/index访问
    在这里插入图片描述
  • 最后注意一点,这个域名只有自己可以访问,别人访问不了,真正的是需要买的,这个就是模拟一下。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值