Nginx Management
Pigsty installs Nginx on INFRA nodes as the entry point for all web services. It listens on standard ports 80/443.
In Pigsty, you can configure Nginx to provide various services through inventory:
- Expose web interfaces for monitoring components like Grafana, VictoriaMetrics (VMUI), Alertmanager, and VictoriaLogs
- Serve static files (software repos, documentation sites, websites, etc.)
- Proxy custom application services (internal apps, database management UIs, Docker application interfaces, etc.)
- Automatically issue self-signed HTTPS certificates, or use Certbot to obtain free Let’s Encrypt certificates
- Expose services through a single port using different subdomains for unified access
Basic Configuration
Customize Nginx behavior via infra_portal parameter:
infra_portal is a dictionary where each key defines a service and the value is the service configuration.
Pigsty generates Nginx configuration files only for services with a defined domain.
home: Special default server for homepage and built-in monitoring component reverse proxies- Proxy services: Specify upstream service address via
endpointfor reverse proxy - Static services: Specify local directory via
pathfor static file serving
Server Parameters
Basic Parameters
| Parameter | Description |
|---|---|
domain | Optional proxy domain |
endpoint | Upstream service address (IP:PORT or socket) |
path | Local directory for static content |
scheme | Protocol type (http/https), default http |
domains | Additional domain list (aliases) |
SSL/TLS Options
| Parameter | Description |
|---|---|
certbot | Enable Let’s Encrypt cert management, value is cert name |
cert | Custom certificate file path |
key | Custom private key file path |
enforce_https | Force HTTPS redirect (301) |
Advanced Settings
| Parameter | Description |
|---|---|
conf | Select a template in roles/infra/templates/nginx |
cache_dir | Development sources can create the cache directory; other deployments must prepare it and its permissions manually |
config | Custom Nginx snippet in a generic template |
index | Enable directory listing (for static) |
log | Custom log file name |
websocket | Enable WebSocket support |
auth | Enable Basic Auth |
realm | Basic Auth prompt message |
When conf is set, that template takes precedence. Otherwise, the role selects a generic template based on home, path, and endpoint.
Configuration Examples
Reverse Proxy Services
Static Files and Directory Listing
Custom SSL Certificate
Using Let’s Encrypt Certificates
Force HTTPS Redirect
Custom Config Snippet
Management Commands
Domain Resolution
Three ways to resolve domains to Pigsty servers:
- Public domains: Configure via DNS provider
- Internal DNS server: Configure internal DNS resolution
- Local hosts file: Modify
/etc/hosts
For local development, add to /etc/hosts:
Pigsty includes dnsmasq service, configurable via dns_records parameter for internal DNS resolution.
HTTPS Configuration
Configure HTTPS via nginx_sslmode parameter:
| Mode | Description |
|---|---|
disable | Listen HTTP only (nginx_port) |
enable | Also listen HTTPS (nginx_ssl_port), default self-signed cert |
enforce | Force redirect to HTTPS, all port 80 requests get 301 redirect |
For self-signed certificates, several access options:
- Trust the self-signed CA in browser (download at
http://<ip>/ca.crt) - Use browser security bypass (type “thisisunsafe” in Chrome)
- Configure proper CA-signed certs or Let’s Encrypt for production
Certbot Certificates
Pigsty supports using Certbot to request free Let’s Encrypt certificates.
Enable Certbot
- Add
certbotparameter to services ininfra_portal, specifying cert name - Configure
certbot_emailwith a valid email - Set
certbot_signtotruefor auto-signing during deployment
Manual Certificate Signing
Or run the scripts directly on the server:
For more info, see Certbot: Request and Renew HTTPS Certificates
Default Homepage
Pigsty’s default home server provides these built-in routes:
| Path | Description |
|---|---|
/ | Homepage navigation |
/ui/ | Grafana monitoring dashboards |
/vmetrics/ | VictoriaMetrics VMUI |
/vlogs/ | VictoriaLogs log query |
/vtraces/ | VictoriaTraces tracing |
/vmalert/ | VMAlert alerting rules |
/alertmgr/ | AlertManager alert management |
/blackbox/ | Blackbox Exporter |
/pev | PostgreSQL Explain visualization |
/haproxy/<cluster>/ | HAProxy admin interface (if any) |
These routes provide one entry point for all monitoring components. You do not need to configure multiple domains.
Best Practices
- Use domain names instead of IP:PORT for service access
- Properly configure DNS resolution or hosts file
- Enable WebSocket for real-time apps (e.g., Grafana, Jupyter)
- Enable HTTPS for production
- Use meaningful subdomains to organize services
- Monitor Let’s Encrypt certificate expiration
- Use
configparameter for custom Nginx configurations
Full Example
Here’s the Nginx configuration used by Pigsty’s public demo site demo.pigsty.io:
Development Maintenance Reference
The specialized development templates below maintain Pigsty’s public sites and are not yet included in public sources. Ordinary portals can use the generic configuration above.
Specialized site templates and migration notes
conf | Purpose and Configuration |
|---|---|
repo.conf | Public package repository; path selects the publication directory. Exposes only listed directories/files, disables directory listings, and rejects unknown Host / SNI |
beta.conf | Proxy cache for Pigsty, PGDG, distribution, and Docker repositories; cache_dir selects the cache directory, with an 80 GiB cache limit and at least 100 GiB free space |
demo.conf | Demo reverse proxy using endpoint, WebSocket support, one-hour read/write timeouts, and disabled response buffering |
pgext.conf | Extension catalog reverse proxy using endpoint, connection reuse, and response buffering |
pgweb.conf | Chinese PostgreSQL community website using endpoint; optional static directories admin_static, media_root, and files_root |
Development files reside in roles/infra/templates/nginx/. All redirect HTTP to HTTPS while retaining the ACME challenge path. Upstream domains, cache limits, and the CA path in beta.conf are template settings. Its default CA path is EL’s /etc/pki/tls/certs/ca-bundle.crt; adapt the template before moving to Debian / Ubuntu. pgweb.conf serves the community website, not the PostgreSQL browser application of the same name.
repo.conf includes a default server and the 127.0.0.1:9180/nginx status endpoint. Do not also generate a home.conf default server on the same listening address. Set nginx_exporter_scrape_uri: http://127.0.0.1:9180/nginx for this template. If overriding nginx_status_port, update the scrape URL too.
The role creates the cache directory only when configuration explicitly provides a nonempty cache_dir. Set it explicitly for beta.conf, for example /data/beta, and verify sufficient data-disk space first.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)