We are going to explain how to configure a nginx proxy to redirect wildfly port 8443 to 443 and redirect requests from application context path to domain name.
The following basic configuration it goes in http context and the base file without can be downloaded here.
This file is created on /etc/nginx/conf.d/wildfly-basic.conf with following command
# cd /etc/nginx/conf.d
# curl https://www.nginx.com/resource/conf/jboss-basic.conf > wildfly-basic.conf
proxy_cache_path /tmp/NGINX_cache/ keys_zone=backcache:10m;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream wildfly {
# Use IP Hash for session persistence
ip_hash;
# List of Wildfly application servers(in case load balancing)
server localhost:8443;
}
server {
listen 443;
server_name domain.com;
# Redirect all HTTP requests to HTTPS
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl http2;
server_name domain.com;
ssl_certificate /etc/nginx/ssl/<certificate-name>;
ssl_certificate_key /etc/nginx/ssl/<private-key>;
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers on;
# Load balance requests for '/webapp/' across Wildfly application servers
location /webapp/ {
proxy_pass http://wildfly;
proxy_cache backcache;
}
# Return a temporary redirect to '/webapp/' when user requests '/'
location = / {
return 302 /webapp/;
}
# WebSocket configuration
location /wstunnel/ {
proxy_pass https://jboss;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Once the file is created we use include directive in the http context of the main file, located /etc/nginx/nginx.conf to read the contents.
http {
...
include conf.d/wildfly-basic.conf;
}
This full example has been collect from the NGINX documentation web page for further information.
Testing new configuration
We can test our conf file with the following commands as test and without reloading configuration on real server.
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# nginx -t -c mynginx.conf
The second command is able to test an specific configuration file.
Reloading updated configuration
Once the configuration is tested we can reload to take effect.
# nginx -s reload
or
# service nginx reload
How to start, stop, reload nginx
We can interact with nginx through various methods on linux, with SystemD, an older system EOLed or nginx signals.
$ sudo systemctl start nginx
$ sudo systemctl restart nginx
$ sudo systemctl stop nginx
$ sudo systemctl status nginx
$ sudo service nginx start
$ sudo service nginx restart
$ sudo service nginx stop
$ sudo nginx -s reload
$ sudo nginx -s stop