0

I am really new to apache2 and have previously worked with Nginx. I am trying to use alias in apache2 to serve static content. Starting off with a simple example.

I tried this out and it didn't work either. Advice?

000-default.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName 13.67.35.134
    Alias /static /home/ubuntu/static
    <Directory /home/ubuntu/static/>
        Options FollowSymLinks
    </Directory>
    ProxyPass / http://127.0.0.1:5000/
</VirtualHost>

I tried it with quotes too based on this answer:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName 13.67.35.134
    Alias /static "/home/ubuntu/static"
    <Directory "/home/ubuntu/static">
        Options FollowSymLinks
    </Directory>
    ProxyPass / http://127.0.0.1:5000/
</VirtualHost>

I have logo.png located at

/home/ubuntu/static/logo.png

alias_module is enabled:

$ apache2ctl -M | grep alias
 alias_module (shared)

When I type in 13.67.35.134/static/logo.png, I get a 404, this is the access.log

[26/Jan/2018:02:31:02 +0000] "GET /static/logo.png HTTP/1.1" 404 423 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"

Solution

Thanks @AndrewSchulman for pointing out that the Proxy Pass in my 000-default.conf file threw off the ability to access my static content.

LLL
  • 3
  • 1
  • 3

2 Answers2

1

I see this is resolved but for anyone else coming across this and needing to keep the ProxyPass config, you can specify to ignore the static URL (at some point between the Alias and ProxyPass config lines, add ProxyPass /static !). (Related q&a regarding static files & ProxyPass here)

Jen
  • 11
  • 1
1

Unless you have another web server running on localhost:5000 (and I don't know why you'd do that, except for testing I guess), you should remove the ProxyPass / http://127.0.0.1:5000/ directive.

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47