大网数据广告活动
服务器运维问答

'localhost' vs. '127.0.0.1' for Apache 2's 'ServerName'

· 52CE 我爱测

Some users report that Apache 2 on Windows is running slow over the network. I know that I was able to speed up MySQL by using 127.0.0.1 for the MySQL connection address. I also found that in a ServerName that is localhost:80 . I…

问题原文

原帖链接 · Chris Muench · CC BY-SA 4.0

Some users report that Apache 2 on Windows is running slow over the network. I know that I was able to speed up MySQL by using 127.0.0.1 for the MySQL connection address. I also found that in a ServerName that is localhost:80.

If I change ServerName to 127.0.0.1:80 will this cause any side effects with networking from machines on the network?

What are the pros and cons of making this change?

已采纳解答

原帖链接 · sa289 · CC BY-SA 4.0

If that's the default VirtualHost, either by being the first VirtualHost defined on that IP address/port combination or because the VirtualHost tag contains _default_ (see VirtualHost Examples - Using default vhosts - Apache HTTP Server), then it shouldn't matter if you change it from localhost:80 to 127.0.0.1:80.

As it stands now, remote machines shouldn't be able to access it anyway using the name localhost (i.e., users wouldn't go to http://localhost unless they were on the machine itself) since that would resolve to their machine and not the machine you're running Apache on.

Since they're not using localhost to access it, changing it shouldn't matter as the default VirtualHost in Apache will field incoming requests regardless of what you put for ServerName or ServerAlias.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-07-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。