The PHP Android App cannot access the web API hosted by vagrant homestead

Invalid Sign

My question: I can access the web API hosted by vagrant homestead through the web browser installed in the host OS X Mac. My homestead also has two laravel websites ll5.app and tapi.app (this is the API)

 _____________Mac OS X on MB Pro___________________
|  _______________            ______________      |
| | Vagrant       |          |              |     |
| |http://api.app | <------> | Web Browser  |     | IP: 192.168.1.7
| |_______________|          |______________|     |
|_________________________________________________|

But, I still Couldn't fix this up for the following:

 _____________Mac OS X on MB Pro_______________________
|  __________________            ________________      |
| | Vagrant          |          |                |     |
| |http://api.app    | <---X--> | Android App    |     |
| | IP:192.168.10.10 |          |IP:192.168.56.1 |     |
| |__________________|          |________________|     |
|______________________________________________________|

My host files are as follows:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
192.168.10.10   ll5.app
192.168.10.10   tapi.app

The following is just a part of my homestead.yaml:

folders:
    - map: "/Users/randika/Private_Projects/webapps/"
      to: "/home/vagrant/webapps"

sites:
    - map: tapi.app
      to: "/home/vagrant/webapps/test_api/public"
    - map: ll5.app
      to: "/home/vagrant/webapps/ll5/public"

I try to give the following to try to make a web service call using the retrofit library

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("<address>")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

For the <address> I tried giving following values:
        http://tapi.app
        192.168.10.10:8000

When I try to access this address using genymotion Android's web browser, the address is http://192.168.10.10:8000 It will load the LL5. App home page instead of the API

How to solve this problem? Appreciate any help. At least just tell me it can't be done?

Note: it's already 1 a.m. since last weekend, I've been struggling for it!

resolvent:

I don't have to give up this problem and solve it once and for all, because when I need to host something and share it openly among my colleagues, I'm tired of looking for a web trustee

Answer: This includes the following:

What must be done:

>Modify host file > Modify nginx file in TRAMP

Optional to DOS:

>Create an atlas account and share access using the tramp sharing feature to access your vagrant homestead lavel development applications anywhere in the world over the Internet

Step by step:

1. Introduce my Mac vagrant homestead environment

Current IP address of my host MacBook: 192.168.1.7

Vagrant homestead IP I defined in homestead.yaml: 192.168.10.10

I have told me in my question that I have multiple sites (LL5. App and TAPI. APP). Therefore, the following is a part of my homestead.yaml, which maps multiple sites

folders:
     - map: "/Users/randika/Private_Projects/webapps/"
       to: "/home/vagrant/webapps"

 sites:
     - map: tapi.app
       to: "/home/vagrant/webapps/test_api/public"
     - map: ll5.app
       to: "/home/vagrant/webapps/ll5/public"

OK, now we can continue to step 2. Sorry, the above part of the hosts file is not in code format due to an editor error

2. I modified the host file as follows:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
192.168.10.10   tapi.app
192.168.10.10   ll5.app
192.168.1.7     192.168.10.10

And save it

3. Start your homeless and supply

 cd Homestead/
 vagrant up
 vagrant provision

4. Let's edit the nginx file in the tramp. Log in to the tramp through SSH

 vagrant ssh

You should see the vagrant SSH prompt as follows: vagrant @ Homestead: ~$

5. Now let's edit the nginx configuration file for each preconfigured vagrant managed web application

 cd /etc/Nginx/sites-available
 ls

You will see the following list of web application configurations (based on my settings):

 ll5.app  tapi.app

In these two web applications, I want to access tapi.app through Android genymotion, but even if I provide vagrants Virtual@R_ 78_ 2419 @ IP or vagrant IP address, and I can't access it because I host multiple sites in vagrant homestead. If it is a single site setting, you can access it through vagrant IP address. Obtain the required nginx config files related to the application as follows: (this step assumes that you know the basics of vim editor)

 sudo vim tapi.app     ----> This will give you the chances to edit that Nginx config file.

As follows:

server {
  listen 80;
  listen 443;
  server_name tapi.app;
  root "/home/vagrant/webapps/test_api/public";

And change it to the following:

server {
  listen 80 default_server;
  listen 443 default ssl;
  server_name tapi.app;
  root "/home/vagrant/webapps/test_api/public";

I want you to notice the following two lines:

 listen 80;    to    listen 80 default_server;
 listen 443;   to    listen 443 default ssl;

OK, now save the nginx config file and exit from the VIM editor

6. Now, the last basic command will be executed in idle SSH:

sudo service Nginx reload

If you follow the above steps for the last step, you may have found the answer to the question now (after trying to solve this problem with less sleep time in the past five nights, I got the answer to my question: D). Note: after reloading nginx, do not configure vagrant, because if you do so, the above nginx configuration file will be rewritten through your editing

matters needing attention:

Please remember that we edit the nginx config file only to enable one of our sites to provide services by default through the server. Therefore, we perform these steps only because we have multiple sites in the vagrant homestead box. Therefore, after completing the required operations, we should roll back the changes made to the specific nginx config file, For further readings please read the following thread

Optional to DOS:

>Suppose you want to develop a project (WEB API or web application) under vagrant homestead and want to share it with your colleagues through the Internet? And you also have another bunch of websites (which is why we struggled in the above steps). Therefore, we can also call it (useless share). Therefore, I have edited the nginx file and informed the server which site I need to use as the default site. Therefore, through vagrant sharing, we can now provide services for the site through the shared URL. Therefore, let's start:

Visit this link is just to give us some background about what we want to do

Homeless sharing steps:

>Visit the following link and create your atlas account. > just exit from vagrant SSH by typing exit, and then log in to vagrant in the homestead directory as follows:

Tramp login > provide your atlas account details (user name and password) when prompted. > the last step of tramp sharing is to share itself. Proceed as follows:

Tramp share

This should provide you with the following results with a globally accessible temporary URL that continues until you stop sharing with the CTRL C command

I hope this answer will help others and save their lives

Cheer for all the engineers on this planet!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>