How to use Confinity with nginx
Configuration as Reverse Proxy
Nginx Configuration
The following configuration is a good starting point when nginx is used as a reverse proxy.
http {
map $http_connection $connection_upgrade {
"~*Upgrade" $http_connection;
default keep-alive;
}
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:5000; # <- where your application is running
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# asset app upload
client_max_body_size 10M;
# Configuration for WebSockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cache off;
# WebSockets were implemented after http/1.0
proxy_http_version 1.1;
# Configuration for ServerSentEvents
proxy_buffering off;
# Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds
proxy_read_timeout 100s;
}
}
}
It is very important having the three marked lines in the configuration, so the application can access the original host, schema and source IP address of the HTTP request. Otherwise Confinity won't be able to create links with correct schema and hostnames.
Application Configuration
In order your application will work properly with a reverse proxy, you have to configure the Forwarded Headers Middleware accordingly. Add the following line before any other middleware.
app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
You can find more information about the configuration for the Forwarded Headers Middleware in the official documentation .
Important if the proxy and the application are not running on the same
machine, you have to configure the properties KnownNetworks or KnownProxies in the ForwardedHeadersOptions.
// example
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor
| ForwardedHeaders.XForwardedProto
| ForwardedHeaders.XForwardedHost;
options.KnownProxies.Add(IPAddress.Parse("192.168.66.225"));
});
...
app.UseForwardedHeaders();