Question

Laravel & Nuxt hosted on vps - same domain how to access laravel storage and api?

Posted October 12, 2020 952 views
ApacheVue.jsLaravel

Hello,

I would like to host my nuxt app which has a Laravel backend on my VPS. I have done it and it works but when I have my .conf file for domain setup like this:

    <IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName xxxxxxxxx
Redirect permanent / https://xxxxxxxxx/
</VirtualHost>
<VirtualHost *:443>
    ServerName xxxxxxxxx
    ServerAlias www.xxxxxxxxx
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/htmlxxxxxxxxx/public

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

    # has Nuxt runs on port 3000
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    RewriteEngine on

    <Directory /var/www/html/xxxxxxxxx/public/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/livexxxxxxxxx-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxxxxxxx-0001/privkey.pem
</VirtualHost>
</IfModule>

The nuxt app works and server-side rendering is enabled but none of my api calls on my domain work.

That could be solved by api subdomain but how can I access my laravel files stored in /storage?

I have run php artisan storage:link but I cannot get the files to show because the nuxt server is I believe kill request to the laravel part.

Can anybody help, please?

Thank you.

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

Indeed one option is to setup the Laravel application on a subdomain name for example: api.your_domain.com.

That way the two applications will be separate and would have separate Apache virtual hosts.

Another option is to setup an alias for your Laravel application inside the Apache Vhost that you shared:

     Alias /app /var/www/laravel/public

That way your Laravel appliation would be accessible at yourdomain.com/app.

Note that you will also need to change your Laravel APP_URL to APP_URL=http://yourdomain.com/app and if you have an .htaccess file you will need to change the following:

// ...
RewriteEngine On

# Add this line
RewriteBase /app/
// ...

Hope that this helps!
Regards,
Bobby