我正在尝试使用docker作为xampp的替代品。我有一个目录结构,我的所有项目都是这样的:
Work
|- project_1
|- public_html
|- project_2
|- public_html
|- etc.
|- httpd # this is where config files lie
我希望能够通过docker部署apache / php并使用主“Work”文件夹作为“htdocs”。当我通过localhost访问项目时(例如,http://localhost/project_1/public_html),它 NOT 工作(给我一个404错误),而同样的事情在xampp和mamp上完全正常。当我访问http://localhost/project_1/时,目录索引也显示正常;我花了4天时间试图弄清楚我做错了什么,但我还是没能。这似乎是apache配置的一个问题,因为相同的项目可以使用xampp和mamp。
httpd文件夹包含以下docker配置文件:
搬运工-compose.yml:
version: '3'
services:
php:
build: .
image: php:7.2-apache
environment:
ALLOW_OVERRIDE: 'true'
DEBUG: 'true'
ports:
- "80:80"
- "443:443"
volumes:
- ../:/var/www/html/
- ./apache.conf:/etc/apache2/sites-available/000-default.conf
的apache.conf:
ServerName localhost
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerAlias localhost
UseCanonicalName Off
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Dockerfile:
FROM php:7.2-apache
COPY httpd.conf /usr/local/apache2/conf/httpd.conf
RUN apt-get update && apt-get install -y --fix-missing \
xz-utils \
build-essential \
pkg-config \
git-core \
autoconf \
libjpeg62-turbo-dev \
libsodium-dev \
libpng-dev \
libcurl4-openssl-dev \
libpq-dev \
libpspell-dev \
libsqlite3-dev \
libmagickwand-dev \
libzip-dev \
imagemagick \
subversion \
python \
g++ \
curl \
vim \
wget \
netcat \
chrpath
RUN docker-php-ext-install \
iconv \
-j$(nproc) sodium \
opcache \
curl \
gd \
mysqli \
pdo \
pdo_pgsql \
pdo_mysql \
pdo_sqlite \
pspell \
pgsql \
soap \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
RUN pecl install imagick && docker-php-ext-enable imagick
WORKDIR /tmp
RUN wget https://getcomposer.org/composer.phar
RUN mv composer.phar /bin/composer
RUN chmod 700 /bin/composer
RUN apt-get clean
RUN apt-get autoremove -y
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/src/*
RUN a2enmod rewrite headers cache cache_disk expires vhost_alias userdir
RUN service apache2 restart
RUN service apache-htcacheclean start
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
WORKDIR /var/www/html
CMD ["apache2-foreground"]
EXPOSE 80
的httpd.conf:
ServerRoot "/etc/apache2"
ServerAdmin postmaster@localhost
ServerName localhost:80
Listen *:80
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_lock_module modules/mod_dav_lock.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule cache_disk_module modules/mod_cache_disk.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule speling_module modules/mod_speling.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so
LoadModule version_module modules/mod_version.so
LoadModule userdir_module modules/mod_userdir.so
<IfModule unixd_module>
User www-data
Group www-data
</IfModule>
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<Files ".ht*">
Require all denied
</Files>
ErrorLog /var/log/apache2/error.log
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog /var/log/apache2/access.log combined
</IfModule>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi .pl .asp
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
<IfModule mime_magic_module>
MIMEMagicFile "conf/magic"
</IfModule>
Include conf/etc/httpd-mpm.conf
Include conf/etc/httpd-multilang-errordoc.conf
Include conf/etc/httpd-autoindex.conf
Include conf/etc/httpd-languages.conf
Include conf/etc/httpd-userdir.conf
Include conf/etc/httpd-info.conf
Include conf/etc/httpd-vhosts.conf
Include "conf/etc/httpd-proxy.conf"
Include "conf/etc/httpd-default.conf"
<IfModule proxy_html_module>
Include conf/etc/proxy-html.conf
</IfModule>
Include conf/etc/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
AcceptFilter http none
AcceptFilter https none
<IfModule mod_proxy.c>
<IfModule mod_proxy_ajp.c>
Include "conf/etc/httpd-ajp.conf"
</IfModule>
</IfModule>
.htaccess(例如在/ project_1 / public_html目录中):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_1/public_html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^.*\.(css|jpe?g|gif|png|js|ico|ttf|woff|woff2)$ [NC]
RewriteRule ^ index.php [QSA,L]
</IfModule>
我真的很感激这方面的一些帮助。我不太熟悉apache,而且刚刚开始使用docker。提前谢谢!