开发者

Redirect a frontend URL to another backend webserver

开发者 https://www.devze.com 2023-03-02 14:42 出处:网络
I\'m using a framework that 开发者_运维百科uses a full-stack to display all its webpages. This runs standard on port 9000. Very fine, but when going into production, the server seems to block everythi

I'm using a framework that 开发者_运维百科uses a full-stack to display all its webpages. This runs standard on port 9000. Very fine, but when going into production, the server seems to block everything except a few standard ports.

So therefore, the framework (Play framework), advises you to do this in your front-end webserver (in my case Apache2).

file: play.conf

<VirtualHost *:80>
  ServerName http://avon.ugent.be
  CustomLog /var/www/log/proxy-access.log common
  ErrorLog /var/www/log/proxy-error.log
  ProxyPreserveHost On
  DocumentRoot /var/www
  <Location /dev/app>
    AuthType Basic
    AuthName "Test Omgeving"
    AuthUserFile /var/trac/htpasswd
    Require valid-user

    ProxyPass http://127.0.0.1:9000/
    ProxyPassReverse http://127.0.0.1:9000/
  </Location>
</VirtualHost>

This of course requires the mod_proxy module, that is being enabled with a2enmod mod_proxy. (I run this on a Debian distro)

The idea is to run two webservers, one front-end and one back-end with the application. The reloading of the apache webserver works fine, the site is enabled and everything, but when I surf to the http://my.website.com/dev/app url, it renders a 404... Suggestions what's going wrong?


EDIT3: After 10+ hours of trying it boils down to this: I found the debugging command (finally :p) and this is the output:

apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server avon.ugent.be (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost avon.ugent.be (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost avon.ugent.be (/etc/apache2/sites-enabled/play.conf:1)
Syntax OK

Which indicates that the virtual server is indeed being added to the configuration. But still, it renders a 404. Now, somewhere i've read that's because there is no index.html in that path. Is that necessary if you just want to use a reverse proxy?


For a start please try using Location instead of Directory. Directory is used for identifying directory paths on the filesystem not paths relative to the document root.

<Location '/dev/app'>
  AuthType Basic
  AuthName "Test Omgeving"
  AuthUserFile /var/trac/htpasswd
  Require valid-user
</Location>


Try the following. It should prompt for the username/password and then pass the request to http://127.0.0.1:9000. In my case, Apache gives a "Service Temporarily Unvavailable", which you should get as well if you turn off the application running on port 9000

<VirtualHost *:80>
    ServerName my.website.com

    <Location /dev/app>
      AuthType Basic
      AuthName "Test Omgeving"
      AuthUserFile passwd/.htpasswd
      Require valid-user

      ProxyPass http://127.0.0.1:9000
      ProxyPassReverse http://127.0.0.1:9000
    </Location>
</VirtualHost>

If you still get a 404, can you confirm that it's not the backend server sending it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号