【发布时间】:2021-12-19 07:10:42
【问题描述】:
我正在本地机器上做一个小项目(在 nginx docker 容器中),今天我第一次将它上传到我的网络服务器并发现它是一个 apache 服务器。
一切正常,除了我的 router.php。
当我访问 example.com/admin 时,我在我的 apache 服务器上收到一个错误 404,但在我的 nginx docker 容器中我得到了正确的页面。 p>
我的error_log_apache 中收到了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.
<?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 USERNAME@uber.space
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>
【问题讨论】:
-
您尝试过什么解决问题的方法?是导致重定向的 PHP 脚本,还是 Apache 本身?