Virtual host mapping could not be resolved for host

Enonic version: 6.14.3
OS: Ubuntu 16.04

I have installed the app as service and I can see that it is up and running. I am now trying to forward port 80 to 8080 without sucess. It does work for http://xxx.sa-east-1.compute.amazonaws.com but for some reason, it does not for ofornecedor.com.br. Any ideas why?

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyRequests Off
#    ServerName xxx.sa-east-1.compute.amazonaws.com --> it works here
    ServerName ofornecedor.com.br
#    ServerAlias xxx.compute.amazonaws.com
    ServerAlias http://ofornecedor.com.br -- does not work for some reason
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

enabled = true

mapping.api.host = localhost
mapping.api.source = /api
mapping.api.target = /api

# mapping.a.host = xxx.sa-east-1.compute.amazonaws.com
mapping.a.host = ofornecedor.com.br
mapping.a.source = /admin
mapping.a.target = /admin
mapping.a.userStore = system

# mapping.b.host = xxx.sa-east-1.compute.amazonaws.com
mapping.b.host = ofornecedor.com.br
mapping.b.host = localhost
mapping.b.source = /
mapping.b.target = /portal/master/ofornecedor

Is there a better way to have enonic to listen to port 80 without redirecting it?

THx in advance

THe question here is how do I make the app to listen to port 80 instead of 8080?

Seems you have two host lines in config. So I asume localhost is being used by the server

mapping.b.host = ofornecedor.com.br
mapping.b.host = localhost

//runar

@rbrastad silly mistake. you are right, I’ve corrected my mistake and now I can access the site on port 8080. What is the best practice to make the app to listen to 80? Redirecting using apache or setting up some other way?

Hi,

For PROD I always use a frontend HTTP server. But for simple POC and TEST I just change the jetty config file.

//Runar

Here is documentation on how to use Apache as a reverse proxy.
https://xp.readthedocs.io/en/6.15/operations/reverse-proxy.html

@tsi @rbrastad Thank you for your help. I will take a look at it. :+1:

I came up with the following config.

vhost

enabled = true

mapping.api.host = localhost
mapping.api.source = /api
mapping.api.target = /api

mapping.a.host = ofornecedor.com.br
mapping.a.source = /admin
mapping.a.target = /admin
mapping.a.userStore = system

mapping.b.host = ofornecedor.com.br
mapping.b.source = /
mapping.b.target = /portal/master/ofornecedor

000-default.config

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyRequests Off

    ServerName ofornecedor.com.br
    ServerAlias http://ofornecedor.com.br
    
    ProxyPass /admin/event ws://localhost:8080/admin/event
    ProxyPassReverse /admin/event ws://localhost:8080/admin/event
    
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Do you see anything wrong here? It is not redirecting to port 8080.

I have ec2 instance created pointing to a domain in Route 53 hosted zone. I am not sure if this has something to do with.

I am receiving

Virtual host mapping could not be resolved for host [www.ofornecedor.com.br] and path [/]

from the server, however I can access the site on port 8080 ( www.ofornecedor.com.br:8080/#/dashboard ).

Very strange. :thinking:

@tsi @rbrastad can we use nginx instead of apache2? I can’t really figure out the issue here, so I was thinking to give a try on nginx.

If you can reach port 8080, at least your firewalling must be wrong.

We use apache2 for everything in enonic cloud, so that will work.

Is there support for writing server aliases with http in front?

Your problem is that you also allow traffic for www.*** to reach xp. Either create a rewrite rule in apache, or add another mapping to XP

@tsi thank you for your reply. Thanks to you I can now access the site on Default Web Site Page :grinning: but not if I try www.ofornecedor.com.br/#/dashboard (www)

Your problem is that you also allow traffic for www.*** to reach xp. Either create a rewrite rule in apache, or add another mapping to XP

…which mapping should I add to XP?

This is the actual config I have in the server. What Am I missing here in order to allow the site to be accessible using www.ofornecedor.com.br/#/dashboard ? :thinking:

enabled = true

mapping.api.host = localhost
mapping.api.source = /api
mapping.api.target = /api

mapping.a.host = ofornecedor.com.br
mapping.a.source = /admin
mapping.a.target = /admin
mapping.a.userStore = system

mapping.b.host = ofornecedor.com.br
mapping.b.source = /
mapping.b.target = /portal/master/ofornecedor

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyRequests Off

    ServerName ofornecedor.com.br
    ServerAlias http://ofornecedor.com.br

    ProxyPass /admin/event ws://localhost:8080/admin/event
    ProxyPassReverse /admin/event ws://localhost:8080/admin/event

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

This is how I would do it.
ServerAlias is what should hold the www alternative

The first three lines after RewriteEngine on is a better way to do proxypass for websocket.
If you need websocket for the whole site, change the lines

   RewriteCond %{REQUEST_URI} / [NC]
   RewriteRule /admin/(.*) ws://exp:8080/$1 [P,L]

You need to add the rewrite module. I have the line as I think it should be. But I usually enable it by running a2enmod rewrite in the server shell

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

<VirtualHost *:80>
   ServerName ofornecedor.com.br
   ServerAlias www.ofornecedor.com.br

   ProxyPreserveHost On
   ProxyRequests Off
   ProxyPass / http://localhost:8080/
   ProxyPassReverse / http://localhost:8080/

   RewriteEngine on

   RewriteCond %{HTTP:Upgrade} =websocket [NC]
   RewriteCond %{REQUEST_URI} /admin [NC]
   RewriteRule /admin/(.*) ws://exp:8080/admin/$1 [P,L]

   RewriteCond %{HTTP_HOST} !^ofornecedor\.com\.br$
   RewriteCond %{HTTP_HOST} !^$
   RewriteRule ^/(.*) http://ofornecedor.com.br/$1 [L,R]

</VirtualHost>

Edit:
Added LoadModule line

1 Like

Redacted (but not deleted due to reply to this message)

@dap thank you so much. The config above worked perfectly . :+1:

2 Likes

This topic was automatically closed after 9 hours. New replies are no longer allowed.