简体   繁体   English

Apache2 Ubuntu:虚拟主机重定向到本地主机

[英]Apache2 Ubuntu: Virtualhost redirects to localhost

I wanted to set up a virtualhost for my apache2 running on my computer. 我想为在计算机上运行的apache2设置一个虚拟主机。 So when I browse to: "invision.jan.pcsg" I get the page contents/folder structure from "/var/www/html/invision" 因此,当我浏览到“ invision.jan.pcsg”时,我从“ / var / www / html / invision”获取页面内容/文件夹结构

This is the virtualhost file "invision.jan.pcsg.conf" I created: 这是我创建的虚拟主机文件“ invision.jan.pcsg.conf”:

<VirtualHost invision.jan.pcsg:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/invision
    ServerName invision.jan.pcsg 
    ServerAlias hkl.mor.pcsg hkl_at.mor.pcsg


    <Directory />
            Options FollowSymLinks
            AllowOverride FileInfo
    </Directory>
    <Directory /var/www/html/invision/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

When I browse to "invision.jan.pcsg" now, I get redirected to localhost and the "php is working"-page is displayed. 现在,当我浏览到“ invision.jan.pcsg”时,将重定向到localhost,并显示“ php is working”页面。

When browsing to "jan.pcsg" the folder contents of "/var/www" is displayed. 浏览到“ jan.pcsg”时,显示“ / var / www”的文件夹内容。

Does anyone have an idea why this happens? 有谁知道为什么会这样?

Change your DocumentRoot to directory where your web application ('view' if its MVC) is located. 将您的DocumentRoot更改为Web应用程序所在的目录(如果是其MVC,则为“查看”)。 Usually its : DocumentRoot /home/www-data/ / 通常是:DocumentRoot / home / www-data /

I had the same issue but in my case I realized I had forgotten to enable the host .conf file. 我遇到了同样的问题,但就我而言,我意识到我忘记了启用主机.conf文件。

sudo a2ensite myvhost.conf

Then I just reloaded apache and everything worked out as expected. 然后,我只是重新加载了Apache,一切都按预期进行了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM