[英]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.