deepnpisgah
New Pleskian
- Server operating system version
- Ubuntu 22.04
- Plesk version and microupdate number
- 18.0.59.2
I would am running FastAPI ASGI applications on my virtual host managed by Plesk. Phusion Passenger is available but only supports WSGI. NGINX Unit can run WSGI and ASGI python applications. I already have several Flask apps running in Phusion Passenger via Apache, but if I switch to NGINX Unit I can run both WSGI and ASGI from one application server (and other Frameworks too). But there's no way via Plesk to configure NGINX as reverse proxy for NGINX Unit because it needs to insert configuration into either Location{} or Server { Location{} } and that's not allowed where the Includes are available via Plesk - since the http{} configuration is already closed by then (Server and Location live inside http{} as in http{ Server { Location{} } }).
Based on how nginx configuration gets generated by plesk I have dropped a file names zz020_myasgiconfig.conf into /etc/nginx/conf.d and so as part of configuration generation it gets included just after zz010_psa_nginx.conf and I can add my own server{} directive.
server {
listen <myip> ssl http2;
ssl_certificate /opt/psa/var/certificates/xyz12345;
ssl_certificate_key /opt/psa/var/certificates/xyz12345;
server_name api.myhost.com;
location /api/myapp/ {
rewrite ^/api/myapp/(.*) /$1 break;
proxy_pass http://127.0.0.1:<app port in UNIT>;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
It works and it is 'configuration regneration proof' - but I have a few questions before calling it a total solution.
1) Will the /etc/nginx/conf.d directory get changed (or my zz020... file deleted) on a Plesk upgrade or update?
2) The only part of my conf that needs to adapt over time is the ssl_certificate and ssl_certificate_key which will change when a new certificate is generated, is there some hook or include within the Plesk infrastructure I can use to get that updated as an include? Otherwise I would need to periodically update my conf file to reflect the current certificates.
thanks!
Based on how nginx configuration gets generated by plesk I have dropped a file names zz020_myasgiconfig.conf into /etc/nginx/conf.d and so as part of configuration generation it gets included just after zz010_psa_nginx.conf and I can add my own server{} directive.
server {
listen <myip> ssl http2;
ssl_certificate /opt/psa/var/certificates/xyz12345;
ssl_certificate_key /opt/psa/var/certificates/xyz12345;
server_name api.myhost.com;
location /api/myapp/ {
rewrite ^/api/myapp/(.*) /$1 break;
proxy_pass http://127.0.0.1:<app port in UNIT>;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
It works and it is 'configuration regneration proof' - but I have a few questions before calling it a total solution.
1) Will the /etc/nginx/conf.d directory get changed (or my zz020... file deleted) on a Plesk upgrade or update?
2) The only part of my conf that needs to adapt over time is the ssl_certificate and ssl_certificate_key which will change when a new certificate is generated, is there some hook or include within the Plesk infrastructure I can use to get that updated as an include? Otherwise I would need to periodically update my conf file to reflect the current certificates.
thanks!