search
Homephp教程php手册localhost与127.0.0.1的区别,localhost127.0.0.1

localhost与127.0.0.1的区别,localhost127.0.0.1

  今天新开了一个服务器,代码挪移过去的时候,竟然数据库连接不上,看了一下,原来将配置从127.0.0.1改为localhost就可以了。看看下面这两个的区别。  

  很多人会接触到这个ip地址127.0.0.1。也许你会问127.0.0.1是什么地址?其实127.0.0.1是一个回送地址,指本地机,一般用来测试使用。大家常用来ping 127.0.0.1来看本地ip/tcp正不正常,如能ping通即可正常使用。

  对于大多数习惯用localhost的来说,实质上就是指向127.0.0.1这个本地IP地址。在操作系统中有个配置文件将localhost与127.0.0.1绑定在了一起。可以理解为本地主机的意思。

 localhost与127.0.0.1的区别是什么?

相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析。

看来这个问题还有人不清楚,其实这两者是有区别的。

localhost也叫local ,正确的解释是:本地服务器

127.0.0.1在windows等系统的正确解释是:本机地址(本机服务器)

他们的解析通过本机的host文件,windows自动将localhost解析为127.0.0.1

localhot(local)是不经网卡传输!这点很重要,它不受网络防火墙和网卡相关的的限制。

127.0.0.1是通过网卡传输,依赖网卡,并受到网络防火墙和网卡相关的限制。

一般设置程序时本地服务用localhost是最好的,localhost不会解析成ip,也不会占用网卡、网络资源。

有时候用localhost可以,但用127.0.0.1就不可以的情况就是在于此。猜想localhost访问时,系统带的本机当前用户的权限去访问,而用ip的时候,等于本机是通过网络再去访问本机,可能涉及到网络用户的权限。

原文参考于:http://blog.csdn.net/xifeijian/article/details/12879395

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft