简体   繁体   中英

Apache Virtual Host multiple routes

We have a VUE front end that is within the dist (var/www/dev/dist) folder. We successfully set up when users visit dev.domain.com that it hits the dist folder. The problem we are having is with our api, which is in an api subfolder (var/www/dev/api/public). What we are trying to accomplish is when the URL dev.domain.com/api is called it points to /var/www/dev/api/public and will also handle all requests appended to api (dev.domain.com/api/*).

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    Servername dev.domain.com
    ServerAlias dev.domain.com

    Alias /api /var/www/dev/api/public

    <Directory /var/www/dev/api>
            Options All
            AllowOverride All
            order allow,deny
            allow from all
    </Directory>

    DocumentRoot /var/www/dev/dist

    <Directory "/var/www/dev">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/dev-domain.log

    # Possible values include: debug, info, notice, warn, errot, crit
    # alert, emerg.
    LogLevel warn

    Customlog ${APACHE_LOG_DIR}/dev-domain-access.log combined

</Virtualhost>

After some more researching and help from the above comment I ended up getting it to work with the following Virtual Hosts config.

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    Servername dev.domain.com

    DocumentRoot /var/www/dev/dist/

    <Directory "/var/www/dev/">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    Alias /api/ "/var/www/dev/api/public/"
    <Directory "/var/www/dev/api/public/">
            Options Indexes FollowSymLinks
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/dev-domain.log

    # Possible values include: debug, info, notice, warn, errot, crit
    # alert, emerg.
    LogLevel warn

    Customlog ${APACHE_LOG_DIR}/dev-domain-access.log combined

</Virtualhost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM