1

Following the instruction here, my website can display the contents fine. However, handling the form submission is current a problem.

I have virtual host set up in my environment. Rendering of contents is fine but form submission ends up in a blank page.

My form is at http://mysite.local/contact

My virtual host is http://mysite.local matches to http://localhost:8080/site

My form follows the developer trail:

<@hst.actionURL var="actionUrl"/>
<form id="" class="form" action="${actionUrl}" method="post">

When I click submit, I was redirected to a blank page: http://localhost:8080/contact?r14_r1_r1:u_u_i_d=5641b2fe-10ad-41b2-8f30-06d8a59ff451

Using my custom component, I printed out the serverName and it's "localhost"!

How do I configure it's in the Console so that my server is "mysite.local" instead of "localhost"?

@Override
public void doBeforeRender(final HstRequest request,
final HstResponse response)
throws HstComponentException {
super.doBeforeRender(request, response);

l.info(request.getServerName());

}

Updates: I've added the node as per Joeren's suggestion. enter image description here

However it's still not working. I event removed the "localhost" node that was orginally under hst:hosts >> dev-localhost but it broke the Site site.

I've noticed that "hst:hosts" have hst:defaulthostname set to "localhost". I haven't dared to make the change because it would be irreversible I thought. enter image description here

Updates:

My virtual host configuration (nginx) is as follows:

server {
      # listen 80;
      server_name mysite.local;

      location /site/ {
        proxy_pass   http://localhost:8080/site/;
        # include /etc/nginx/proxy_params;
      }

      location /cms/ {
        proxy_pass   http://localhost:8080/cms/;
        # include /etc/nginx/proxy_params;
      }

      location / {
        proxy_pass   http://localhost:8080/site/;
        # include /etc/nginx/proxy_params;
      }
    }
ericn
  • 12,476
  • 16
  • 84
  • 127

2 Answers2

1

To redirect to the fully qualified domain name you will need to setup the virtual host in the HST configuration tree in the CMS JCR console.

If the mysite.local is a domain on your local machine you can place it in the dev-localhost host group. By creating the following nodes:

hst:hst + hst:hosts + dev-localhost + local + mysite + hst:root

See the hosts configuration documentation for more background information. If you have a web server in front like apache make sure you leave the proxypreserve host on, so that the HST can detect the host. See the Apache webserver configuration documentation for more information.

Jeroen
  • 3,076
  • 1
  • 17
  • 16
0

Passing the host name solve the problem! Thanks to Jeroen's comment.
There is no need to update the hst:hosts configurations in the console though.

I've updated my nginx config to as follows:

server {
      # listen 80;
      server_name mysite.local;

      location /site/ {
        proxy_pass   http://localhost:8080/site/;
        proxy_set_header Host            $host;
        proxy_set_header X-Forwarded-For $remote_addr;
      }

      location /cms/ {
        proxy_pass   http://localhost:8080/cms/;
        proxy_set_header Host            $host;
        proxy_set_header X-Forwarded-For $remote_addr;
      }

      location / {
        proxy_pass   http://localhost:8080/site/;
        proxy_set_header Host            $host;
        proxy_set_header X-Forwarded-For $remote_addr;
      }
    }
ericn
  • 12,476
  • 16
  • 84
  • 127