hack3rcon
(Hack3rcon)
March 23, 2024, 11:49am
1
Hello,
I have a YAML file as follows:
version: '3.9'
networks:
phpnet:
driver: bridge
services:
web:
image: nginx:latest
ports:
- '8080:8080'
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /var/www/html:/usr/share/nginx/html
networks:
- phpnet
links:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- /var/www/html:/usr/share/nginx/html/
networks:
- phpnet
I also have an Apache container as follows:
version: '3.9'
services:
httpd:
ports:
- '80:80'
volumes:
- '/var/www/html:/usr/local/apache2/htdocs/'
image: 'httpd:latest'
I want Apache to use the PHP container. I know that I should use external: true in the first container, but I don’t know the rest of the steps.
Cheers.
hack3rcon
(Hack3rcon)
March 24, 2024, 1:38pm
2
Hello,
I changed the configurations as below:
version: '3.9'
networks:
phpnet:
driver: bridge
name: My_Network
services:
web:
image: nginx:latest
ports:
- '8080:80'
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /var/www/html:/usr/share/nginx/html
networks:
- phpnet
depends_on:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- /var/www/html:/usr/share/nginx/html/
- /var/www/html:/usr/local/apache2/htdocs/
networks:
- phpnet
And:
version: '3.9'
networks:
apache:
external: true
name: My_Network
services:
httpd:
ports:
- '80:80'
volumes:
- /var/www/html:/usr/local/apache2/htdocs/
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf
image: 'httpd:latest'
networks:
- apache
The network is also built by Docker:
# docker network list
NETWORK ID NAME DRIVER SCOPE
b36954410da3 My_Network bridge local
385e912fff96 bridge bridge local
7b3a9c0ec7dd host host local
fb5635eda3c3 nginx-php_phpnet bridge local
d851ead577b7 none null local
b13678883aac redis_default bridge local
Nginx can translate the PHP file, but Apache can’t:
# curl http://172.20.2.58:8080/index.php
Testing PHP-FPM on Docker.
#
# curl http://172.20.2.58:80/index.php
<?php
echo "Testing PHP-FPM on Docker."
?>
Is this error related to the network?
Cheers.
hack3rcon
(Hack3rcon)
March 25, 2024, 1:29pm
3
Hello,
The problem was solved by adding the following lines to the httpd.conf file:
LoadModule proxy_module modules/mod_proxy.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule proxy_module>
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://php-fpm:9000"
</FilesMatch>
</IfModule>