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

How does ServerName and ServerAlias work?

· 52CE 我爱测

It's the following part of a virtual host config that I need further clarification on: <VirtualHost *:80> # Admin email, Server Name (domain name), and any aliases ServerAdmin [email omitted] ServerName 141.29.495.999 ServerAlias…

问题原文

原帖链接 · njp · CC BY-SA 3.0

It's the following part of a virtual host config that I need further clarification on:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email omitted]
  ServerName  141.29.495.999
  ServerAlias example.com
...

This is and example config, similar to what I currently have (I don't have a domain name at the moment).

<VirtualHost *:80> - Allow the following settings for all HTTP requests made on port 80 to IPs that this server can be contacted on. For instance, if the server could be accessed on more than one IP, you could restrict this directive to just one instead of both.

ServerName - If the host part of the HTTP request matches this name, then allow the request. Normally this would be a domain name that maps to an IP, but in this case the HTTP request host must match this IP.

ServerAlias - Alternate names accepted by the server.

The confusing part for me is, in the above scenario, if I set ServerAlias mytestname.com and then made an HTTP request to mytestname.com, there would have to be a DNS record pointing to the server's IP for this to work? In which case, is ServerAlias just basically EXTRA ServerName entries?

Say I had a DNS entry such that foobar.com = 141.29.495.999 but then I had ServerName = 141.29.495.999 and ServerAlias was empty, would that mean that although foobar.com gets resolved to the right IP, because there is no reference to accept foobar.com in ServerName or ServerAlias?

Or something. Man I'm confused.

社区高分解答

原帖链接 · Gajendra Sharma · CC BY-SA 4.0

<VirtualHost *:80>
    ServerName influenceknowledge.test
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/work-force/public
    ServerAlias influenceknowledge.test *.influenceknowledge.test
    <Directory /var/www/html/influence-knowledge/public >
       AllowOverride All
           Require all granted
    </Directory>    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

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

资料来源与适用范围

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

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

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