Ubuntu Apache2 local virtual hosts url not found

别来无恙 提交于 2021-02-08 04:01:51

问题


I am setting up my laptop for single-user development of multiple sites using the LAMP stack on Ubuntu 16.10 with virtual hosts for the different sites, and name-based virtual hosts. I have tried various combinations of config settings, but I cannot load a site from the Browser, I get "the requested URL was not found on this server." Here are relevant code snippets from relevant config files:

Ports.conf:

Listen 8000

apache2.conf:

NameVirtualHost *:8000
ServerName localhost
...

.../sites-enabled/000-default.conf:

<VirtualHost *:8000>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
...

.../sites-enabled/abc.conf:

<VirtualHost *:8000>
ServerName abc
ServerAdmin admin@abc.com
ServerAlias www.abc.com abc.com
DocumentRoot /var/www/abc

.../sites-enabled/pbnat.conf:

<VirtualHost *:8000>
ServerName pbnat
ServerAdmin admin@pbnat.com
ServerAlias pbnat.com pbn.com
DocumentRoot /var/www/pbnat/public
...

/etc/hosts

127.0.0.1   localhost
127.0.1.1   Lenovo-y2-11
127.0.0.1   abc
127.0.0.1   pbnat

Dir Struct:

/var/www/
   |-- abc/
       |- index.html
   |-- html/
       |- index.html
   |-- pbnat/
       |-- public/
           |- index.html

Permissions on /var/www/:

drwxr-xr-x 2 www-data julie 4096 Jan  8 16:53 abc
drwxrwxr-x 2 root     root  4096 Dec 31 00:02 html
drwxrwxr-x 3 www-data pbnat 4096 Jan  6 22:32 pbnat

Permissions on /var/www/abc/:

-rw-r--r-- 1 www-data julie 139 Jan  8 16:53 index.html

Permissions on /var/www/html/:

-rwxrwxr-x 1 root root 11321 Dec 31 00:02 index.html

Permissions on /var/www/pbnat/:

drwxrwxr-x 2 www-data pbnat 4096 Jan  7 00:00 public

Browser URL tests and results:

file:///var/www/abc/index.html - Success! The abc virtual host is working!

file:///var/www/pbnat/public/index.html - Success! The pbnat virtual host is working!

localhost – site can’t be reached; localhost refused to connect.

localhost:8000 – Apache2 Ubuntu default page

localhost:8000/abc - The requested URL /abc was not found on this server.

localhost:8000/abc.com - The requested URL /abc.com was not found on this server.

  • then I changed the IP to 127.0.0.2 in hosts file for the new sites but left localhost as 127.0.0.1 and tried:

127.0.0.2:8000 - Apache2 Ubuntu default page

127.0.0.2:8000/abc – The requested URL /abc was not found on this server.

Error log shows nothing unusual, Access log shows HTTP status code of 404, along with a second code of 495 or 496; also it lists 127.0.0.1 in the first column of the log even if I enter 127.0.0.2:8000/abc

Been going at this quite some time. Help much appreciated.


回答1:


The problem was based in how the URL is entered in the browser. It should be: abc:8000 Not: localhost:8000/abc



来源:https://stackoverflow.com/questions/41540206/ubuntu-apache2-local-virtual-hosts-url-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!