[英]How can i deploy my website on Heroku properly?
我正在嘗試將我的網站部署在 Heroku 上,我用於此的實現是 Model 我不知道發生了什么,但是當我嘗試訪問主頁(或索引)時,效果很好,當我嘗試訪問 mi 網站上的其他頁面時,會發生如下情況:
我知道發生這種情況的一個原因,我在路由器中使用了下一個:
$currentURL = $_SERVER['PATH_INFO'] ?? '/';
//var_dump($_SERVER);
$method = $_SERVER['REQUEST_METHOD'];
if($method === 'GET'){
$fn = $this->routesGET[$currentURL] ?? null;
} else{
$fn = $this->routesPOST[$currentURL] ?? null;
}
所以,我在我的網站上顯示了 PHP $_SERVER 的全局變量,我注意到$_SERVER['PATH_INFO']
沒有出現在上面。 所以,我想問題出在 Apache 的配置上,因為我為此使用了 Apache2 和 PHP。 所以,我不知道如何配置,因為這是我第一次這樣做,如果你能幫助我,我會非常感謝你。
這是我的目錄:在此處輸入圖像描述
最后,我的 procfile:
web: vendor/bin/heroku-php-apache2 public/
這些是配置基於 MVC 的 web 應用程序的一般適用步驟。 假定 web 服務器版本用於以下設置: Apache HTTP Server v2.4 。
1) 阻止對所有目錄和文件的訪問:
首先,在Apache的配置文件中,默認禁止所有目錄和文件的訪問:
# Do not allow access to the root filesystem.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
# Prevent .htaccess and .htpasswd files from being viewed by Web clients.
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
2)允許訪問默認目錄:
然后應該允許訪問應該用於項目的默認目錄(此處為/var/www/
):
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
我的建議:出於安全原因,這個位置應該只包含一個index.php
和一個index.html
文件,每個文件都顯示一個簡單的“Hello”消息。 所有 web 項目應在其他目錄中創建,並應單獨設置對它們的訪問權限,如下所述。
3)設置對單獨項目目錄的訪問:
假設您在默認位置( /var/www/
)之外的另一個位置(例如目錄/path/to/my/sample/mvc/
)創建項目。 然后,考慮到只有子文件夾public
應該可以從外部訪問,為它創建一個 web 服務器配置,如下所示:
ServerName www.my-sample-mvc.com
DocumentRoot "/path/to/my/sample/mvc/public"
<Directory "/path/to/my/sample/mvc/public">
Require all granted
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
請注意,上述設置可以定義為:
如果使用虛擬主機定義文件,則必須在標簽<VirtualHost>
和</VirtualHost>
之間包含設置:
<VirtualHost *:80>
... here come the settings ...
</VirtualHost>
注意:每次更改配置設置后,不要忘記重新啟動 web 服務器。
一些資源:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.