-1

The app is on a Payara server and with a context root nocodeapp-web-front-1.0

I don't want to have this context root in the url. This nginx config gives the intended result for the index page of the app (it is live at https://test.nocodefunctions.com):

upstream payara {
    least_conn;

    server localhost:8080 max_fails=3 fail_timeout=5s;
    server localhost:8181 max_fails=3 fail_timeout=5s;
}
server {
    if ($host = test.nocodefunctions.com) {
        return 301 https://$host$request_uri;
    }


    listen        80;
    access_log /var/log/nginx/payara-access.log;
    error_log /var/log/nginx/payara-error.log;
    
    client_max_body_size 100M;
    server_name   test.nocodefunctions.com;
    return        301 https://$host$request_uri;


}

server {
    listen        443 ssl;
    server_name   test.nocodefunctions.com;
    client_max_body_size 100M;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";

    location /nocodeapp-web-front-1.0 {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_no_cache $cookie_nocache  $arg_nocache$arg_comment;
            proxy_no_cache $http_pragma     $http_authorization;
            proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
            proxy_cache_bypass $http_pragma $http_authorization;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host:$server_port;
            add_header Access-Control-Allow-Origin *;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_pass http://payara$request_uri;
    }
    
    location = / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://payara/nocodeapp-web-front-1.0$request_uri$is_args$args;
    }

    ssl_certificate /etc/letsencrypt/live/xxxxxx/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xxxxxx/privkey.pem; # managed by Certbot
}

However when we navigate in the app by clicking on the "Go" button, the page at /choosefunction.html appears as:

https://test.nocodefunctions.com/nocodeapp-web-front-1.0/choosefunction.html

...the subpath nocodeapp-web-front-1.0 reappeared?

How can I get:

https://test.nocodefunctions.com/choosefunction.html

NB: I have checked these two questions 1 & 2, they don't work for me

seinecle
  • 101
  • 4

1 Answers1

1

You need to specify the application's root URL in the application configuration. This will make the application generate correct URLs for links and resources.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
  • Payara automatically defines a root URL, which is the name of the war file: https://stackoverflow.com/a/51172500/798502 In my case this is "nocodeapp-web-front-1.0". Or I misunderstood your answer? – seinecle May 16 '21 at 13:27
  • You need to override the contextroot like expolained in the answer you linked. nginx can change HTML contents and replace URLs, but it is unreliable and can lead to hard to discover bugs. It is best to fix the application. – Tero Kilkanen May 17 '21 at 06:08
  • Thank you this is what I ended up doing: setting the context root to an empty String. For Payara this can be done by appending a ":" to the war file when deploying: https://docs.payara.fish/community/docs/documentation/payara-micro/deploying/deploy-cmd-line.html In JSF, an empty context root causes resource files not to load if you are using the "library" tag, see: https://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used#comment119423219_11988418 – seinecle May 17 '21 at 06:47