VPS 上的 Web 應用程式。如何讓它出現在子網域上?

VPS 上的 Web 應用程式。如何讓它出現在子網域上?

我正在使用個人 VPS(Ubuntu 20、Apache2)來託管 Web 應用程式。目前有 2 個靜態站點,site1.com 和 site2.org,都在運作。

我安裝了一個目前在連接埠 8065 上可用的應用程序,例如:site2.org:8065

我的問題是,如何設定 Apache 以使該應用程式出現在mm.site2.org? (帶有子域“mm”)。

我創建了一個像這樣的設定檔:

# /etc/apache2/sites-available/mm.site2.org.conf
<VirtualHost *:80>
    ServerName mm.site2.org

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


    ProxyRequests Off
    <Proxy http://localhost:8065/*>       
      Order deny,allow
      Allow from all
    </Proxy>
        
    ProxyPass / http://127.0.0.1:8065/
    ProxyPassReverse / http://127.0.0.1:8065/

    <Location />
      Order allow,deny
      Allow from all
    </Location>

</VirtualHost>

設定上述內容後,我執行了必要的命令來重新啟動服務,如下所示:

sudo a2ensite mm.site2.org.conf
sudo systemctl reload apache2
sudo service apache2 restart

我還嘗試了 Apache conf 檔案中該行的變體<Proxy ...>,基於一些不同的來源,簡單地<Proxy *>按照一些來源的建議使用。

如果相關的話,我的 DNS 設定僅由每個網站的兩個 A 記錄 (@www) 組成。

的輸出sudo apache2ctl -S是:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 12.345.67.890. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server site1.com (/etc/apache2/sites-enabled/site1.com-le-ssl.conf:2)
         port 443 namevhost site1.com (/etc/apache2/sites-enabled/site1.com-le-ssl.conf:2)
                 alias www.site1.com
         port 443 namevhost site2.org (/etc/apache2/sites-enabled/site2.org-le-ssl.conf:2)
                 alias www.site2.org
*:80                   is a NameVirtualHost
         default server 12.345.67.890 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 12.345.67.890 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost site1.com (/etc/apache2/sites-enabled/site1.com.conf:1)
                 alias www.site1.com
         port 80 namevhost site2.org (/etc/apache2/sites-enabled/site2.org.conf:1)
                 alias www.site2.org
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

沒有運氣讓網路應用程式出現在所需的子網域上。

答案1

根據您所寫的內容,我認為 DNS 配置不正確:

如果相關的話,我的 DNS 設定僅包含每個網站的兩個 A 記錄(@ 和 www)。

您必須為子網域新增 DNS RR,位址:mm.site2.org. A 12.345.67.890或 cname(別名):mm.site2.org. CNAME www.site2.org.。要將所有子網域定向到此伺服器,RR 名稱可以是通配符:*.site2.org. A 12.345.67.890(CNAME RR 可能也足夠了)。 (看來你期望它已經像這樣工作了。)

相關內容