Skip to main content

Parse Nginx configurations in a clear manner for debugging purposes

Project description

Nginx Static Analysis

nginx-static-analysis

Parse Nginx configurations on your host and filter for directives/values.

Largely powered by Crossplane.

Analysing your Nginx configuration

You can list any directive within your Nginx configuration. For example, show all listen directives:

app@wifbtb-testalex-magweb-cmbl:~$ nginx-static-analysis directive listen
+------------------------------------------------------+----------------------------------------+------------------+
|                         File                         |                 Values                 |    Directives    |
+------------------------------------------------------+----------------------------------------+------------------+
|  /etc/nginx/sites/http.testalex.hypernode.io.conf:4  |     127.0.0.1:1337 default_server      | server -> listen |
| /etc/nginx/sites/http.testalex.hypernode.io.conf:16  |          8888 default_server           | server -> listen |
| /etc/nginx/sites/https.testalex.hypernode.io.conf:6  | 127.0.0.1:443 ssl http2 default_server | server -> listen |
| /etc/nginx/sites/https.testalex.hypernode.io.conf:22 |     8443 ssl http2 default_server      | server -> listen |
+------------------------------------------------------+----------------------------------------+------------------+

Filtering also works for values, like showing all location blocks with value /:

app@wifbtb-testalex-magweb-cmbl:~$ nginx-static-analysis directive location --values /
+----------------------------------------------------+--------+------------------------------------------+
|                        File                        | Values |                Directives                |
+----------------------------------------------------+--------+------------------------------------------+
|            /etc/nginx/testsite.conf:18             |   /    |  http -> include -> server -> location   |
| /etc/nginx/sites/http.testalex.hypernode.io.conf:8 |   /    |            server -> location            |
|            /etc/nginx/magento2.conf:17             |   /    | server -> include -> include -> location |
+----------------------------------------------------+--------+------------------------------------------+

You can search for multiple directives, as long as you specify >=n-1 values to directives. F.e., find the server_names and locations that match with location=/static/:

app@wifbtb-testalex-magweb-cmbl:~$ nginx-static-analysis directive location server_name --value /static/
+------------------------------------------------------+-----------------------+------------------------------------------+
|                         File                         |         Values        |                Directives                |
+------------------------------------------------------+-----------------------+------------------------------------------+
|             /etc/nginx/monitoring.conf:5             |       localhost       | http -> include -> server -> server_name |
|              /etc/nginx/testsite.conf:5              |         magweb        | http -> include -> server -> server_name |
| /etc/nginx/sites/https.testalex.hypernode.io.conf:21 | testalex.hypernode.io |          server -> server_name           |
|             /etc/nginx/magento2.conf:23              |        /static/       | server -> include -> include -> location |
+------------------------------------------------------+-----------------------+------------------------------------------+

By default it parses /etc/nginx/nginx.conf and all includes, but you can specify the starting file:

app@wifbtb-testalex-magweb-cmbl:~$ nginx-static-analysis -f /some/other/nginx.conf directive location
...

Feeding logs into the analysis

You can feed access/error logs into the analysis by piping it into stdin:

app@wifbtb-testalex-magweb-cmbl:~$ tail /var/log/nginx/access.log -n1 | nginx-static-analysis d location
+----------------------------------------------------+--------+------------------------------------------+
|                        File                        | Values |                Directives                |
+----------------------------------------------------+--------+------------------------------------------+
|            /etc/nginx/testsite.conf:18             |   /    |  http -> include -> server -> location   |
| /etc/nginx/sites/http.testalex.hypernode.io.conf:8 |   /    |            server -> location            |
|            /etc/nginx/magento2.conf:17             |   /    | server -> include -> include -> location |
+----------------------------------------------------+--------+------------------------------------------+

The analysis creates filters based on the incoming loglines. Those filters are combined with the arguments given to the nginx-static-analysis command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nginx-static-analysis-0.1.7.tar.gz (9.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page