簡體   English   中英

在Google Compute Engine上具有IP地址的虛擬主機

[英]Virtual host with IP Address on Google Compute Engine

我已經在Google Compute引擎上創建了LAMP實例,並且該實例較早就可以正常工作,但是一旦創建了生產和開發環境,它便無法正常工作。

我到目前為止所做的如下:

  • 我沒有域,因此它在公共IP地址上運行-例如30.30.30.205

  • 我已經在/ etc / apache2 / sites-available /中創建了development.conf文件。

development.conf的內容如下:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/production/application
    Alias production

    <Directory "/var/www/html/production/application">
              Options Indexes FollowSymLinks MultiViews
              AllowOverride all
              Require all granted
              Order allow,deny
              allow from all
        </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

基於上面的配置,我希望在url中實現的是http://30.30.30.205/production ,對於開發來說,它將類似於http://30.30.30.205/development

我在/ var / www / html中有2個文件夾-在生產和開發環境中設置了不同的環境。

創建配置文件后,我還要在/ sites-enabled文件夾中運行sudo a2ensite命令。

我尚未在/ etc中設置主機,因為我認為我沒有域,但不確定是否在此范圍內,因此如果我需要在此處進行任何操作,請引導我。

按照上述步驟操作后,當我嘗試點擊網址時,我無法訪問Google雲上的網站。

請幫助或指導我如何解決此問題。

如果在嘗試創建虛擬主機之前這是可行的,那排除了防火牆或網絡配置,因此我將專注於apache2方面。

我剛剛嘗試實現與您正在執行的操作類似的操作,並且設法使此功能正常運行,盡管每個虛擬主機的環境都非常簡單。

帖子中需要注意的一件事是,您已經將生產的配置文件命名為“ development.conf”。 將其命名為“ production.conf”(而將開發的conf文件命名為“ development.conf”)是否更有意義。

這是我創建基本工作環境所遵循的步驟。 試試這個,看看它是否有效,如果可以的話,您可以在其上構建。

1)在/ var / www / html /中,我創建了兩個名為“開發”和“生產”的文件夾。

2)在兩個文件夾中,我都創建了一個index.html文件:

/var/www/html/development/index.html

<html>
   <head>
        <p> "This is development" </p>
   </head>
</html>

/var/www/html/production/index.html

<html>
  <head>
          <p> "This is production"
  </head>
</html>

3)在/etc/apache2/sites-available創建兩個名為'development.conf'和'production.conf'的配置文件。

development.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/development

    <Directory "/var/www/html/development">
              Options Indexes FollowSymLinks MultiViews
              AllowOverride all
              Require all granted
              Order allow,deny
              allow from all
    </Directory>

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

</VirtualHost>

production.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/production

    <Directory "/var/www/html/production">
              Options Indexes FollowSymLinks MultiViews
              AllowOverride all
              Require all granted
              Order allow,deny
              allow from all
    </Directory>


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

</VirtualHost>

4)現在,確保您在/ etc / apache2 / sites-available中,並針對創建的兩個配置文件運行以下兩個命令:

$ sudo a2ensite development.conf 

$ sudo a2ensite production.conf 

5)重新啟動apache2:

$ sudo systemctl reload apache2

現在,當您導航到http:// EXTERNAL_IP / development時,您將看到:

"This is development"

同樣,當您瀏覽到http:// EXTERNAL_IP / production時,您將看到:

"This is production"

編輯:

響應您收到的“無法訪問此站點”錯誤,您確定要使用http而不是https搜索地址嗎? 即確保您嘗試在瀏覽器中進行解析:

http://EXTERNAL_IP/development

而不是

https://EXTERNAL_IP/development

值得注意的是,如果您在GCP控制台的“ VM實例”頁面中單擊外部IP地址,它將嘗試使用HTTPS解析該地址,並且如果未配置SSL,則會收到您收到的錯誤消息。

作為另一個故障排除步驟,您只需將基本index.html文件放在/ var / www / html中,然后通過在瀏覽器中導航到http:// EXTERNAL_IP來查看是否可以通過http請求解決。 如果您收到相同的錯誤,則可能是防火牆規則存在問題。

關於您的htaccess配置,我嘗試使用默認配置進行上述操作。 您可能值得一開始嘗試使虛擬主機啟動並運行,然后一次在此之上添加更復雜的配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM