I have my Laravel backend that I am trying to connect to from android app. my hosts file has
127.0.0.1 my.backend.test
the httpd conf file in my backend is
<VirtualHost *:80>
ServerName my.backend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog /var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
Header set Access-Control-Allow-Origin "http://localhost:4200"
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
I can access http://my.backend.test/api/some-route fine from google ARC but not from my phone. I seem to have to use my local ip address but I dont understand how to set that up.
I tried adding
<VirtualHost 192.168.my.ip:8080>
ServerName my.mobilebackend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog
/var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
to httpd conf and
192.168.my.ip my.mobilebackend.test
to hosts
If I understand correctly : you can access your server from a different machine on the same network (so this is not a firewall problem) but only if you use the name (added in client's hosts file) and not the IP address.
Is your configuration the first virtualhost ? apache search for a ServerName
matching the name provided in the query (e.g. the URL), then falls back to the first one, in your case the ubuntu home page.
As a test, what happens if you use
ServerName 192.168.0.1 (i.e. the IP used in the URL)
I think it will work if you access the server by IP address, but not anymore by name
Try this method
ip:port
Example
10.0.2.2:80
Note: Firewalls may cause problems with this. Windows has Microsoft Windows Firewall enabled by default. You may have to disable it
If you are using an emulator:
10.0.2.2
If you are using a real device:
ipconfig
in cmd (if you are using Windows)Default port is 80
. If you have changed it, use the new one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With