简体   繁体   中英

Apache Virtual Host, host webside without alias

I can host a website using Alias.

Than the URI look like: www.myside.com/alias

I achive this using this in /etc/apache2/sites-available/www.myside.com.conf

 Alias /alias"/usr/local/tomcat/alias"
 <Directory "/usr/local/tomcat/alias">
     Options -Indexes -FollowSymLinks
     AllowOverride AuthConfig
     Require all granted
 </Directory>

What I need is that I'm able to host the main context with this: www.myside.com and an image context with the alias, looking like this: www.myside.com/userimg . So I only need the main <Directory></Directory> block without the alias.

By the way, I'm using JKmount.

The image context:

 Alias /userimg "/usr/local/tomcat/userimg"
      <Directory "/usr/local/tomcat/userimg">
         Options -Indexes -FollowSymLinks
         AllowOverride AuthConfig
         Require all granted
      </Directory>

Reading your question, I assume that:

  • your site is not SSL.

  • therefore it will use port 80

  • you have a site, lets say http://www.example.com

  • the files for your site are stored in /usr/local/tomcat/alias

  • the main page for your site is index.html , under /usr/local/tomcat/alias

  • the image files for your site are sorted in /usr/local/tomcat/userimg

  • in your HTML files, you reference other pages like this:

     <a href="otherpage.html">Other page</a>
  • you reference images like this:

     <img src="userimg/someimage.png" alt="Some Image">

Your configuration would look like this:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com

    ErrorLog "logs/error_log"
    CustomLog "logs/access_log" combined

    DocumentRoot "/usr/local/tomcat/alias"
    DirectoryIndex index.html

    Alias "/userimg" "/usr/local/tomcat/userimg"

    <Directory "/usr/local/tomcat/alias">
        Options -Indexes -FollowSymLinks
        AllowOverride AuthConfig
        Require all granted
    </Directory>

</VirtualHost>

If you want to avoid any Alias at all, you could create a softlink in /usr/local/tomcat/alias to /usr/local/tomcat/userimg .

cd /usr/local/tomcat/alias
ln -s /usr/local/tomcat/userimg userimg

And you will have to allow Apache to follow links in the <Directory> directives.


Or you could move your images under /usr/local/tomcat/alias/userimg .

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