Apache在本地主机上工作,但在服务器名上不工作

问题描述 投票:1回答:1

正如我的用户名所示,我是一个新手程序员。

我正在尝试在ubuntu中配置一个简单的Apache服务器。

我在etcapache2sites-availableawesome.conf中创建了下面的.conf文件,代码如下。我还在etcapache2sites-enable中创建了一个符号链接,并重新启动了Apache。

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.myawesome.org

ServerAdmin webmaster@localhost
DocumentRoot /var/www/awesome
DirectoryIndex hello.php


# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

当我访问localhostawesomehello.php时,我得到了想要的文本 "Hello World"。

但是当我输入www.myawesome.org,它就会显示以下信息。"找不到服务器"

Any helpguidance is appreciated.

Regards....

apache localhost
1个回答
3
投票

你需要编辑hosts文件,并在这里添加指向localhost的ServerName。

打开hosts文件,用:

sudo nano /etc/hosts

...并在文件末尾添加:

127.0.0.1 www.myawesome.org
© www.soinside.com 2019 - 2024. All rights reserved.