我正在我的本地機器上(在nginx docker 容器中)上做一個小專案,今天我第一次將它上傳到我的網路服務器并發現它是一個apache服務器。
一切正常,除了我的 router.php。
當我訪問 example.com/admin 時,我在 apache 服務器上收到錯誤404,但在我的nginx docker 容器中,我得到了正確的頁面。
我正在進入AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.我的error_log_apache
<?php
//Router.php
namespace blog;
class Router
public function __construct(private AdminPage $adminPage,
private AdminContentPage $adminContentPage,
private ArticlePage $articlePage,
private VariablesWrapper $variablesWrapper,
private SessionManager $sessionManager){}
public function getPageForUrl() : Page
{
switch ((string)$this->variablesWrapper->getRequestUri()){
case '/admin':
if ($this->sessionManager->isAuthenticated()){
return $this->adminContentPage;
} else {
return $this->adminPage;
}
case preg_match('/\/([A-Za-z]\w )\/\?article\=[0-9]{1,5}/',(string)$this->variablesWrapper->getRequestUri()): //Hello_world/?article=0
default:
return $this->articlePage;
}
}
}
因為它可能與配置有關,而且我必須知道到底是什么,我會給你我的 default.conf,它是我的 nginx 服務器的配置。
server {
listen 80;
index index.php index.twig;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
這是我的 apache 服務器中未修改的 httpd.conf 編輯:顯然我必須有權更改 httpd 配置
# managed by uberspace-generate-httpd-config
<Directory /var/www/virtual/USERNAME>
AllowOverride AuthConfig FileInfo Indexes Limit Options=ExecCGI,Includes,Indexes,MultiViews,SymLinksIfOwnerMatch
Options Includes
</Directory>
<VirtualHost *>
ServerName USERNAME.uber.space
ServerAlias blog.returnnull.de
ServerAlias www.returnnull.de
ServerAlias USERNAME.uber.space
ServerAlias returnnull.de
SuexecUserGroup USERNAME USERNAME
DocumentRoot /var/www/virtual/USERNAME/html
ServerAdmin [email protected]
AllowEncodedSlashes NoDecode
ErrorLog /readonly/USERNAME/logs/error_log_apache
LogLevel notice
RewriteEngine On
# If there is a host-specific pseudo-DocumentRoot, use it instead of the default one
RewriteCond /var/www/virtual/USERNAME/%{HTTP_HOST} -d
RewriteRule (.*) /var/www/virtual/USERNAME/%{HTTP_HOST}$1
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php-fpm-USERNAME.sock|fcgi://php-fpm-USERNAME"
</FilesMatch>
<Proxy "fcgi://php-fpm-USERNAME" max=10>
</Proxy>
</VirtualHost>
uj5u.com熱心網友回復:
您必須.htaccess在專案的根目錄中添加一個檔案。
RewriteBase /
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
為此,您需要為 apache 啟用重寫模塊,您可以通過sudo a2enmod rewrite在此之后運行來執行此操作,您需要重新啟動 apache 服務器sudo service apache2 restart
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349371.html
