basically the title - I used a debian install of apache via docker to create a local web server.
I installed php-fpm and put an index.php into /var/www/mysite/index.php
The enabled 000-default.conf vhost config is this:
<VirtualHost *:80>
ServerName www.test.com
ServerAdmin webmaster@localhost
ServerAlias localhost 127.0.0.1
DocumentRoot /var/www/mysite
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
#Override through .htaccess etc.
<Directory /var/www/mysite>
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Allow from all
Order Deny,Allow
</Directory>
<FilesMatch \.php+$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php8.2-fpm.sock|fcgi://127.0.0.1"
</FilesMatch>
</VirtualHost>
As I understand it, VirtualHost *:80 also should cover 127.0.0.1.
BUT:
Calling localhost/index.php gives my desired file
- 172.29.0.1 - - [19/Feb/2024:20:53:13 +0100] "GET /index.php HTTP/1.1" 200 2288 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
Calling 127.0.0.1/index.php gives me a permanently moved and a subsequent 404
172.29.0.1 - - [19/Feb/2024:20:53:21 +0100] "GET /index.php HTTP/1.1" 302 337 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
172.29.0.1 - - [19/Feb/2024:20:53:21 +0100] "GET /error.php HTTP/1.1" 200 1128 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
The replies have been taken from the access log of my server.
My ports.conf is the default one:
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
I have been searching the web for a couple of days now but I am somehow at my end. What did I miss - how or where can I make 127.0.0.1 behave exactly as a call to localhost does?
I have the feeling that I am handling two different "domains" here with different contexts, but I would like have them both configured the exact same way.
Also, when I put a .htaccess with a redirect into the foder, the 127.0.0.1 rather downloads code instead of handling it as php-code. I got the feeling that 127.0.0.1 is veeery differently configured from the rest of the server - but how so?
Thanks in advance!
Okay, to make it short - usually I expected ServerAlias localhost 127.0.0.1 to be the same as putting those values in separate ServerAlias directives. Possibly, this is not equal.
So fellow googler, if you come this way, check if you put your aliases in the vhost and also if you put them into different lines.