GoDaddy 도움말

How to Setup a name-based virtual host on Fedora 20

This article will show you how to configure a basic Apache Virtual Hosts. If you have a control panel, typically you wont need to follow these steps - but if you would like to learn how to create a website using command line only, this is your e.
DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 15-30+ min
RELATED PRODUCTS Linux-based VPS or dedicated servers

First, we need to create the document root for the virtual host we are about to create. For this example we will use as the domain but you can use one of your own if you have one availible for this project. We will be logged in as root to complete these commands, permissions will be updated as we progress through the setup.

If this is one of many domains you plan on adding to the server, you want to make sure you create a consistent directory structure that you are able to replicate for other domains.

mkdir -p /var/www/ being the domain you selected for this project.

Then we need to create an index file to validate whether or not we setup the Virtual Host correctly.

vi /var/www/

Here is a snippet of code you can use to test your index file.

Virtual Host Is Working

You Have Successfully Configured an Apache Virtual Host on CentOS

Once we have saved that, then we need to run a few commands to ensure that the anonymous visitor from the internet can see your web content. First we need to update the ownership for our website.

chown -R user:user /var/www/

user being a non-root user on your system.

chmod -R 755 /var/www/

That’s it, we have created the foundation in which our domains website content to be served from. Now we need to let Apache know where to serve this content and under what address. On Fedora, we will be modifying the Apache configuration directly, first open the httpd.conf and scroll to the bottom.

vi /etc/httpd/conf/httpd.conf

NameVirtualHost *:80
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.

DocumentRoot /var/www/
ErrorLog /var/www/
CustomLog /var/www/

In this file, we will update a few things - in the example above we have already made these changes.

ServerAdmin - This is your email address, any apache notifications for this website will be sent to this address.

DocumentRoot - This is the document root we created in the beginning of this project, this variable tells Apache where the content is that needs to be served.

ServerName & ServerAlias - This is your domain name with and without the www. as you can see in the example above.

ErrorLog & CustomLog - These are the log locations for your domain name, by filling these in - you can easily parse through error logs on different domains.

Before restarting Apache, you can check your syntax by running the following command:

httpd -S

The output should have the following line, letting you know you added the virtual host correctly.

VirtualHost configuration: (/etc/httpd/conf/httpd.conf:357)

Finally, we need to restart Apache for these changes to take effect.

/etc/init.d/httpd restart

There you have it, you have successfully create an name-based virtual host and can now visit your website on the internet. If you used a real domain, you need to update your DNS to point at your hosted server.

이 글이 도움되었나요?
피드백을 보내주셔서 감사합니다. 고객 서비스 담당자에게 문의하시려면 지원 전화 번호 또는 위의 채팅 옵션을 이용하시기 바랍니다.
도와드릴 수 있어 기쁩니다! 더 도와 드릴 것이 있나요?
그것 유감스럽습니다. 혼동이 되었던 사항 또는 솔루션이 고객님의 문제를 해결하지 못했던 원인을 알려주세요.