How to configure Virtual Host on Ubuntu VPS Server, Laravel + AngularJS?

2

Currently I have a project where I separate the part of the backend and frontend, for the backend I use laravel and for the front I use AngularJS, this separated into two folders api (laravel) api_front (angularjs), both inside the folder project .

When I log into the browser: link I automatically upload the part made with angularjs

since the configuration in the server I have it in this way

/etc/apache2/sites-available/000-default.conf

Virtual Host 1:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/proyecto/api_front/

        <Directory /var/www/html>
            Options Indexes FollowSymLinks
            AllowOverride All
           Require all granted
        </Directory>


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

</VirtualHost>

The problem I have is that in the angularJS project I use WebServices from the part made with laravel. Example of webService: http://ip_servidor/proyecto/api/public/ws/colaboradores but when I consult that Web Service in the browser I get Not Found The requested URL / project / api / public was not found on this server

Then I have created a second Virtual Host:

<VirtualHost *:88>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/proyecto/api/

        <Directory />
                Options FollowSymLinks
                AllowOverride none
        </Directory>

        <Directory /var/www/html/proyecto/api/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride none
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
                DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>
</VirtualHost>

But this new route is still not working. Please can you help me, thank you in advance.

    
asked by JG_GJ 18.03.2018 в 07:27
source

1 answer

0

One solution that occurs to me is that you use the ServerName directive to differentiate both projects. First in / etc / hosts add two aliases for the local host:

127.0.0.1  localhost pr1back pr1front

Now in each of the virtualhosts you have in / etc / apache2 / sites-enabled / add the directive ServerName

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName pr1front
        DocumentRoot /var/www/html/proyecto/api_front/

and in the other:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName pr1back
        DocumentRoot /var/www/html/proyecto/api/

Now from the browser you can access link and link independently and not You will have the problem that you currently have since any request to the root of the projects will be solved correctly.

    
answered by 18.03.2018 в 13:31