0

Let's suppose a scene.

  • domain name: xyz.com
  • the domain parsed by third-party dns server: ns1.xxx.com
  • IP address bound with domain: 123.123.123.123
  • apache2 was installed on 123.123.123.123

Should my /etc/httpd/conf/httpd.conf be this way :

config1:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerName 123.123.123.123:80
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

config2:  

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerName xyz.com:80
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

config3:  

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerName localhost:80
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

config4:  

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerName 127.0.0.1:80
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

Which config file is fit for my example?

0

Apache's ServerName Directive performs the same basic function as nginx's server_name directive, that is, it is compared against the Host parameter in the incoming HTTP request, if it matches that virtual host config is chosen. Importantly it is only used for selection of the virtual host - if the webserver can't resolve the request by the port or IP address of the network interface the webserver is listening on - i.e. ServerName is only used for the selection of the virtual host if this <VirtualHost *:80> doesn't unambiguously resolve to a virtual host/config.

From the docs

Description: Hostname and port that the server uses to identify itself
Syntax: ServerName [scheme://]domain-name|ip-address[:port]

Per your example the ServerName directive would be used in an Apache virtual host config like this:

<VirtualHost *:80>
  ServerName xyz.com
  ...
  ...
  # ...
</VirtualHost>
  • I have changed my question to make it more clearly. – it_is_a_literature Nov 15 '16 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.