[英]getting 404 not found - website with apache2 on ubuntu
Background:背景:
I've installed apache2 and have tried set up virtual directories... but when I try to test the different sites, I keep getting 404 error messages.我已经安装了 apache2 并尝试设置虚拟目录......但是当我尝试测试不同的站点时,我不断收到 404 错误消息。
The article /tutorial I've been following is located at: https://www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps我一直在关注的文章 /tutorial 位于: https : //www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian -vps
I have the following folder structure in place:我有以下文件夹结构:
/var/www/webtest.com/test.html
/var/www/ttimes.com/test.php
In the /etc/apache2/sites-available folder, I have the following configuration files:在 /etc/apache2/sites-available 文件夹中,我有以下配置文件:
jmj@cp-AOA150:/etc/apache2/sites-available$ ls -lah /var/www/
total 44K
drwxr-xr-x 9 root root 4.0K Jul 28 21:37 .
drwxr-xr-x 15 root root 4.0K Jul 28 19:54 ..
drwxr-xr-x 2 root root 4.0K May 11 2013 current
drwxr-xr-x 2 root root 4.0K Apr 3 08:21 html
-rwxr-xr-x 1 root root 177 Nov 23 2013 index.html
-rwxr-xr-x 1 root root 124 Jul 28 20:14 test.php
drwxr-xr-x 5 jmj root 4.0K Jun 6 11:58 ttimes.com
drwxr-xr-x 2 jmj root 4.0K Jul 28 21:21 webtest.com
Here's what the webtest.com.conf file looks like: webtest.com.conf 文件如下所示:
<VirtualHost *:80>
ServerAdmin admin@webtest.com
ServerName webtest.com
ServerAlias www.webtest.com
DocumentRoot /var/www/webtest.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Here's what my hosts file looks like:这是我的主机文件的样子:
127.0.0.1 localhost
127.0.1.1 cp-AOA150
This is all just on a local dev box where I want to have multiple sites located under /var/www.这一切都只是在本地开发箱上,我希望在 /var/www 下有多个站点。 Once the site is developed, I'm going to move them to my hosting company.一旦网站开发完毕,我将把它们转移到我的托管公司。 I currently don't have other IP addresses to add, so I skipped the step of adding VPS server IPs.我目前没有其他IP地址要添加,所以我跳过了添加VPS服务器IP的步骤。
I am able to successfully run the我能够成功运行
sudo a2ensite webtest.com.conf须藤 a2ensite webtest.com.conf
command and I restart apache.命令,然后我重新启动 apache。
But when I go to my site by typing http://localhost/webtest.com/test.html
, I get a 404 not found error.但是当我通过输入http://localhost/webtest.com/test.html
进入我的网站时,我收到 404 not found 错误。
What I've tried so far: - I've reviewed the article to make sure I didn't miss any steps.到目前为止我已经尝试过: - 我已经查看了这篇文章,以确保我没有遗漏任何步骤。 - proved that apache itself is working by going to http://localhost.
- 通过访问http://localhost.
证明 apache 本身正在工作http://localhost.
When I do that, I get a page that reads:当我这样做时,我得到一个页面,上面写着:
Index of /
[ICO] Name Last modified Size Description
Apache/2.4.7 (Ubuntu) Server at localhost Port 80
Then I stop the apache service and try the same URL.然后我停止 apache 服务并尝试相同的 URL。 It fails.它失败。
You might have to edit /etc/apache2/apache2.conf
您可能需要编辑/etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;并将其更改为;
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
then,然后,
sudo service apache2 restart
You may need to also do sudo a2enmod rewrite
to enable module rewrite.”您可能还需要执行sudo a2enmod rewrite
以启用模块重写。”
You have it setup as a virtual host pointing to webtest.com but you're trying to access it through localhost/.您已将其设置为指向 webtest.com 的虚拟主机,但您正尝试通过 localhost/ 访问它。 With a VirtualHost it doesn't exist in that path.使用 VirtualHost 它不存在于该路径中。
The easiest way is to edit your /etc/hosts file to make a local DNS entry for webtest.com.最简单的方法是编辑您的 /etc/hosts 文件,为 webtest.com 创建本地 DNS 条目。 Add a line to that file like this:在该文件中添加一行,如下所示:
127.0.0.1 webtest.com
Then point your browser to webtest.com and you should see your site.然后将您的浏览器指向 webtest.com,您应该会看到您的站点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.