I have a cloud server on which a Widlfly web server is installed with a Nginx as reverse proxy. If I now directly call the application that is deployed on the Widlfly via the IP address port name of the application (ipadress:8080/webapp), everything loads normally and completely
However, if I use the ip address without port and thus the reverse proxy, the UI does not load. The tab header still matches the satrpage that is defined in the application. In the console of Firefox I get the following two error messages:
Loading module from “https://ipadress/VAADIN/build/vaadin-bundle-8b9f3384a0c9fa4e9000.cache.js” was blocked because of a disallowed MIME type (“text/html”)
Uncaught (in promise) TypeError: ServiceWorker script at https:///sw.js for scope https:/// encountered an error during installation.
and an 404 for a GET Request to load an Image:
https://ipadress/webapp/icons/icon-512x512.png
My Nginx widlfly.conf (Path: /etc/nginx/conf.d/) file looks like this:
upstream wildfly {
# List of Widlfly Application Servers
server <ipadress port>;
}
server {
listen 80;
server_name <ipadress>;
# Redirect all HTTP to HTTPS
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl http2;
server_name ipadress;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/planyourplaylist.com.key;
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers on;
# when user requests /
location = / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://<ipadress port>/webapp/;
}
}
The nginx.conf (Path: /etc/nginx/) file looks like this:
http {
include /etc/nginx/conf.d/*.conf;
proxy_cache_path /tmp/NGINX_cache/ keys_zone=backcache:10m;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/sites-enabled/*;
}
I'm not sure if it's the redirection from HTTP to HTTPS or the WAR deployment structure of the project that Nginx doesn't understand.
I apologize for my poor English and thank everyone who takes the time to help me.
CodePudding user response:
The solution was as simple as the problem. The reason for the problem was simply a wrong understanding of nginx. According to my understanding I would have used Nginx to answer requested URLs and redirect them to where I expect them. But that is not the case. If I have understood it correctly now, Nginx refers to the values that are given with the URL and set in the linked Server.
Example: If I have a webapp with the deployment name /start, Nginx must also get this as
location /start{...}
If I set as an example the location to
location /{...}
and set a Proxy_Pass to
localhost:8080/start
,nginx finds the correct page of the server by the /start in the proxy_pass value, but the Server not the correct files to load the page. So the widlfly searches in the Directory of the page "/" and not of the page "/start".
The setting of the url to "/" I have thus achieved via a web.xml (it also works via the Vaadin Javax serverlet). So now I can give nginx the
location / {...}
and will be redirected to the correct page.
Thanks again @Marco C for your help. I hope I could also make Nginx a little clearer to others.