本地主机的别名主机名 [英] Alias hostname for localhost

查看:456
本文介绍了本地主机的别名主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设本地Python脚本正在运行Web服务器.

Assuming that a local Python-Script is running a webserver.

有什么方法可以设置别名,以使http://localwebapp/等于http://localhost:1234/?

Is there any way to set an alias, so that http://localwebapp/ equals http://localhost:1234/?

或者至少http://localwebapp:1234/等于http://localhost:1234/?

推荐答案

当浏览器看到http://localwebapp/时,它首先尝试确定localwebapp的IP地址.如果成功,浏览器将使用一个特定的端口(该端口对于HTTP为80,除非URL中提到了其他端口)建立与该主机的TCP连接.

When the browser sees http://localwebapp/ it first tries to determine the IP address of localwebapp. If this succeeds, the browser establishes a TCP connection with that host, using a specific port (which is 80 for HTTP, unless some other port is mentioned in the URL).

localwebapp解析为IP地址不会考虑端口信息,因此只能通过HTTP重定向将http://localwebapp/指向http://localhost:1234/.

Resolving localwebapp to an IP address does not take port information into account, so pointing http://localwebapp/ to http://localhost:1234/ can only be done by means of a HTTP redirection.

要使http://localwebapp:1234/http://localhost:1234/相同,请通过添加以下行来编辑操作系统的hosts文件

To make http://localwebapp:1234/ the same as http://localhost:1234/, edit the hosts file of your operating system by adding the line

127.0.0.1 localwebapp

hosts文件的位置取决于操作系统.对于类似UNIX的操作系统,通常为/etc/hosts.

The location of the hosts file depends on the operating system. For UNIX-like operating systems, its usually /etc/hosts.

这篇关于本地主机的别名主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆