如何解决Apache2 RewriteRule在图像docker.io/library/php:7.4-apache的容器中不起作用
主要问题:
http://localhost/mysite/source/aPHPfile.PHP
有效。
http://localhost/mysite/aPHPfile
的重写规则,但
我尝试将服务器放在PHP:7.2-apache
运行的PHP:7.4-apache
容器映像中,而docker.io/library/
运行的/var/www/html/mysite/source/aPHPfile.PHP
容器映像中。我两个都有同样的问题。当我在本地尝试时,RewriteRule可以完美运行。我希望它在容器中工作。
磁盘(在内部容器中)的文件夹结构:
.htaccess
不包括/etc/apache2/apache.conf
个文件。
配置:
使用Current Configuration: (from server-info page)
In file: /etc/apache2/sites-enabled/mysite.conf
1: <Directory "var/www/html/mysite/">
7: RewriteEngine On
9: RewriteCond %{REQUEST_FILENAME} !-d
10: RewriteCond %{REQUEST_FILENAME} !-f
11: RewriteRule ^aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L]
: </Directory>
加载时,确认正确的配置:
/etc/apache2/sites-enabled/mysite.conf
还有文件<Directory "var/www/html/mysite/">
Options +Indexes
AllowOverride All
Order allow,deny
Allow from all
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L] # <---- this line works in non-container server despite starting with /var/...
#to be sure,I tried also with ^/aPHPfile ^mysite/aPHPfile
# ^/mysite/aPHPfile in additional lines seperately to point
# to /var/www/html/mysite/source/aPHPfile.PHP [L]
# edit1,include exact lines I tried
# RewriteRule ^aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L] # <---- this line works in non-container server despite starting with /var/...
# RewriteRule ^aPHPfile source/aPHPfile.PHP [L] # <---- this I tried today after comment from @Daniel Farrell but no change in the result
# RewriteRule ^/aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L]
# RewriteRule ^source/aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L]
# RewriteRule ^/aPHPfile /var/www/html/mysite/source/aPHPfile.PHP [L]
</Directory>
:
/var/log/apache2/access.log
日志:
-
127.0.0.1 - - [31/Oct/2020:14:01:36 +0000] "GET /mysite/aPHPfile HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/86.0.4240.111 Safari/537.36"
:
/var/log/apache2/error.log
其他详细信息:
#Dockerfile
FROM debian:buster-slim
RUN apt update -y \
&& apt install -y apache2 PHP PHP-<many extensions> \
&& apt clean all
#copY <source> <dest>
#RUN <a2enmod,a2ensite>
CMD apachectl -D FOREGROUND
这样,所有功能以及重写规则都可以正常工作。
创建新图像:
PHP:7.x-apache
仍然不知道为什么[System.Environment]::SetEnvironmentvariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
[System.Environment]::SetEnvironmentvariable('PYENV_HOME',"User")
[System.Environment]::SetEnvironmentvariable('path',$HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"User")
官方图像不起作用。 (臭虫?)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。