為多個網站設定 Apache VirtualHost

為多個網站設定 Apache VirtualHost

我正在嘗試在我的電腦上建立網站,但遇到了一些麻煩。我已經使用 Flask 和調試伺服器製作了該網站的原型,現在想在進一步調試它的同時託管它一段時間。這僅供我公司網路內部使用。

我似乎無法正確配置 Apache。我目前運行一個連結到我的主目錄的預設站點,因此我可以透過網頁瀏覽器從其他電腦取得檔案。

我根本沒有改變apache2.conf,但這是我的 httpd.conf

<Location /server-status>
    SetHandler server-status

    Order Deny, Allow
    Deny from all
    Allow from .mycompany.com
</Location>

我的預設配置位於 中/etc/apache2/sites-available/default,具有

<VirtualHost *:80>
    ServerAdmin [email protected]

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinksMultiViews
        AllowOverride None
        Order allow,deny
        allow from .mycompany.com
    </Directory>
    <Directory /var/www/home/>
        Options Indexes FollowSymLinks MultiViews
        AllowOVerride None
        Order allow,deny
        allow from .mycompany.com
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

雖然我嘗試啟用的應用程式具有以下配置文件,位於/etc/apache2/sites-available/Powermon

LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so

User p_user
Group p_group
FastCgiServer /home/p_user/Powermon/runp.fcgi -idle-timeout 300 -processes 5

<VirtualHost *:80>
    ServerName powermon
    DocumentRoot /home/p_user/Powermon/app/static
    Alias /static /home/p_user/Powermon/app/static

    AddHandler fastcgi-script fcgi
    ScriptAlias / /home/p_user/Powermon/runp.fcgi

    ErrorLog /home/p_user/Powermon/logs/powermon_error_log

    <Location />
        SetHandler fastcgi-script
    </Location>
</VirtualHost>

在啟用網站內我看到

000-default -> ../sites-available/default

所以我添加了

010-powermon -> ../sites-available/Powermon

當我跑步時apache2ctl -S我看到

VirtualHost configuration:
wildcard NameVirtualHosts and _default_servers:
*:80            is a NameVirtualHost
    default server dhcp-ip-address.mycompany.com (/etc/apache2/sites-enabled/000-default:1)
    port 80 namevhost dhcp-ip-address.mycompany.com (/etc/apache2/sites-enabled/000-default:1)
    port 80 namevhost powermon (/etc/apache2/sites-enabled/010-powermon:7)
Syntax OK

因此,目前當我進入machine-name/瀏覽器時,我可以導航我的主目錄並根據需要查看文件。理想情況下,我希望能夠查看machine-name/powermon我的應用程式正在運行。

答案1

你說你想設定 Apache 虛擬主機,但你這麼說:

因此,目前當我進入machine-name/瀏覽器時,我可以導航我的主目錄並根據需要查看文件。理想情況下,我希望能夠查看machine-name/powermon我的應用程式正在運行。

主機上的路徑不是虛擬主機。您的配置設定如下:流量powermon進入一個配置。流量dhcp-ip-address.mycompany.com轉到另一個配置。

因此,Apache 虛擬主機設定起作用的唯一方法是訪問此 URL 並獲取一件事:

dhcp-ip-address.mycompany.com

然後轉到這個 URL 並獲取另一件事:

powermon

/etc/hosts透過 Apache 虛擬主機設定真正實現此目的的唯一方法是像這樣更改 Web 瀏覽客戶端的檔案。假設這些虛擬主機位於 IP 位址為 123.456.78.90 的伺服器上。打開你的hosts文件——我用的是 Mac,所以我會這樣做——透過nano這樣的方式:

sudo nano /etc/hosts

並將此行新增至文件底部:

123.456.78.90 powermon

現在,當您將網頁瀏覽器指向:

http://powermon

您將獲得已安裝的 Apache 虛擬主機設定。

但是,您再次混淆了伺服器路徑與伺服器虛擬主機的概念。所以你需要在做其他事情之前解決這個問題。另外,您的虛擬主機配置powermon似乎脫節。外面的東西<VirtualHost *:80>應該​​放進去。否則這些配置選項無論如何都會被伺服器範圍的default配置使用。User&設定Group似乎也很混亂。這些腳本應設定為可由 Apache 使用者和群組使用。反之則不然。但假設是善意的,我將這樣建構它:

使用者 p_user 群組 p_group

伺服器名稱 powermon DocumentRoot /home/p_user/Powermon/app/static 別名 /static /home/p_user/Powermon/app/static

    LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so

    FastCgiServer /home/p_user/Powermon/runp.fcgi -idle-timeout 300 -processes 5

    AddHandler fastcgi-script fcgi
    ScriptAlias / /home/p_user/Powermon/runp.fcgi

    ErrorLog /home/p_user/Powermon/logs/powermon_error_log

    <Location />
        SetHandler fastcgi-script
    </Location>

</VirtualHost>

答案2

您確定您建立了檔案的軟連結: /etc/apache2/sites-available/Powermon 嗎?

有些,比如:

cd /etc/apache2/sites-enabled/
ln -s ../sites-available/Powermon

相關內容