Access to virtual host on XAMPP

Hello. I'm used to using portable XAMPP to work with PHP projects. To do this, I configure the hosts file and httpd.config. As a result, I can access the virtual site using its name, not a digital address. If I log in from another local computer, then it is enough to set up a similar hosts file there. But if I try to send a http request from my arduino or esp, I can't do it even if I use a numeric address. I get the code 404. If I remove these settings in the hosts file and httpd.config, then again I can go to the digital address. But I would like to use site names. Unfortunately, I can not configure the DNS service. Can this be configured somehow? And where exactly is it configured?

A 404 code usually means 'page not found', rather than unable to connect.
Do you see a connection from the Arduino in the web server logs?
Is the get/set URL valid?
Is it identical to that generated by a web browser?

If you don't see anything in the logs then install Wireshark and look for inbound connection attempts.

When using names rather than numbers you need a name resolution service. Are you able to set one up on the machine running the web server?

I can't set up the DNS service.

Attempts to connect are visible. But there is a difference. Here is an example if I do not use virtual host names (I use a digital path): "POST /raznoe/postplain.php HTTP/1.1" 200 176 "-" "ESP8266HTTPClient" And here is an example when I use virtual host names configured in the hosts file: "POST /raznoe/postplain.php HTTP/1.1" 404 302 "-" "ESP8266HTTPClient"
I've tried other URL options but none of them work.

Configure your logging format to show the full URL including host name or IP address. The 'Combined Log Format' may be suitable

If you mean this setting:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog "log/access_log" combined

I have just such a setting. I cut out the excess from the log file and show it here.
For the URL, I used the following options:

  1. Only the name, but then nothing gets into the log at all.
  2. Full path including IP, drive letter, here is the result: "/DriveLetter/xampp/httdocs/raznoe/postplain.php HTTP/1.1" 404 302 "-" "ESP8266HTTPClient"

Try
%{Host}i

Some additional thoughts, the log shows that the server is accepting connections using the host name, therefore it means the Arduino is successfully resolving the host name to an IP address the server is listening to. As far I am aware Arduino name resolution is only done using DNS. The 404 probably indicates a problem with how your virtual host is setup, either the IP address or directory path.

Have you checked the URL using a web browser? My guess is that you will see the same 404 error.

I'm afraid you are wrong. Maybe because I'm not very good at explaining (I don't speak English well). Let me explain again and illustrate the situation with new log file settings.
Situation #1. I configure the hosts file and httpd.conf to use virtual site names (eg raznoe). I drive the following lines into the Arduino firmware: #define SERVER_IP "raznoe". I get a response in the monitor POST failed, error: connection failed and there is nothing in the log file.
Situation #2. I configure the hosts file and httpd.conf to use virtual site names (eg raznoe). I drive the following lines into the Arduino firmware: #define SERVER_IP "IP / different" I get a response code 404 in the monitor, and in the log file: "POST /raznoe/postplain.php HTTP/1.1" 404 302 "-" "ESP8266HTTPClient" IP/raznoe/postplain.php"
Situation #3. I configure the hosts file and httpd.conf to use virtual site names (eg raznoe). I drive the following lines into the Arduino firmware: #define SERVER_IP "IP/Drive_Letter/xampp/httdocs/raznoe" I get a response code 404 in the monitor, and in the log file: "POST /DriveLetter/xampp/httdocs/raznoe/postplain.php HTTP/1.1" 404 302 "-" "ESP8266HTTPClient" IP/DriveLetter/xampp/httdocs/raznoe/postplain.php"
Situation number 4. I remove the settings from the hosts and httpd.conf files to use the names of virtual sites. I drive the following lines into the Arduino firmware: #define SERVER_IP "IP / different" I get a response code 200 in the monitor, and in the log file: "POST /raznoe/postplain.php HTTP/1.1" 200 240 "-" "ESP8266HTTPClient" IP/raznoe/postplain.php"
Situation number 5. I remove the settings from the hosts and httpd.conf files to use the names of virtual sites. I drive the following lines into the Arduino firmware: #define SERVER_IP "raznoe" I get a response in the monitor: POST... failed, error: connection failed, but nothing in the log file.
As you can see, in a situation where I use only the virtual host name "raznoe", the arduino cannot connect to the server, there is no mention of this in the log file. These are situations 1 and 5. In situations 2 and 3 I get the code 404. And only in situation 4 I get the code 200.
P.S. POST... failed, error: connection failed is my sketch setup for output to serial monitor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.