@@ -183,9 +183,12 @@ With the advanced syntax, the `exec` subdirective must appear exactly once. The
183183times.
184184
185185The ` except ` subdirective uses the same pattern matching logic that is used
186- with the ` match ` subdirective. Any request that matches a ` match ` pattern is
187- then checked with the patterns in ` except ` , if any. If any matches are made
188- with the ` except ` pattern, the request is rejected.
186+ with the ` match ` subdirective except that the request must match a rule fully;
187+ no request path prefix matching is performed. Any request that matches a
188+ ` match ` pattern is then checked with the patterns in ` except ` , if any. If any
189+ matches are made with the ` except ` pattern, the request is rejected and passed
190+ along to subsequent handlers. This is a convenient way to have static file
191+ resources served properly rather than being confused as CGI applications.
189192
190193The ` empty_env ` subdirective is used to pass one or more empty environment
191194variables. Some CGI scripts may expect the server to pass certain empty
@@ -221,6 +224,64 @@ will be available with the following environment variables
221224All values are conveyed as strings, so some conversion may be necessary in your
222225program. No placeholder substitutions are made on these values.
223226
227+ ### Troubleshooting
228+
229+ If you run into unexpected results with the CGI plugin, you are able to examine
230+ the environment in which your CGI application runs. To enter inspection mode,
231+ add the subdirective ` inspect ` to your CGI configuration block. This is a
232+ development option that should not be used in production. When in inspection
233+ mode, the plugin will respond to matching requests with a page that displays
234+ variables of interest. In particular, it will show the replacement value of
235+ ` {match} ` and the environment variables to which your CGI application has
236+ access.
237+
238+ For example, consider this example CGI block:
239+
240+ cgi {
241+ match /wapp/*
242+ exec /usr/local/bin/wapptclsh /home/quixote/projects{match}.tcl
243+ pass_env HOME LANG
244+ env DB=/usr/local/share/app/app.db SECRET=/usr/local/share/app/secret
245+ inspect
246+ }
247+
248+ When you request a matching URL, for example,
249+
250+ https://example.com/wapp/hello.tcl
251+
252+ the Caddy server will deliver a text page similar to the following. The CGI
253+ application (in this case, wapptclsh) will not be called.
254+
255+ CGI for Caddy inspection page
256+
257+ Executable .................... /usr/local/bin/wapptclsh
258+ Arg 1 ....................... /home/quixote/projects/wapp/hello.tcl
259+ Root .......................... /
260+ Dir ........................... /home/quixote/www
261+ Environment
262+ DB .......................... /usr/local/share/app/app.db
263+ PATH_INFO ...................
264+ REMOTE_USER .................
265+ SCRIPT_EXEC ................. /usr/local/bin/wapptclsh /home/quixote/projects/wapp/hello.tcl
266+ SCRIPT_FILENAME ............. /usr/local/bin/wapptclsh
267+ SCRIPT_NAME ................. /wapp/hello
268+ SECRET ...................... /usr/local/share/app/secret
269+ Inherited environment
270+ HOME ........................ /home/quixote
271+ LANG ........................ en_US.UTF-8
272+ Placeholders
273+ {.} ......................... /home/quixote/go/src/github.com/mholt/caddy/caddy
274+ {host} ...................... example.com
275+ {match} ..................... /wapp/hello
276+ {method} .................... GET
277+ {root} ...................... /home/quixote/www
278+ {when} ...................... 23/May/2018:14:49:55 -0400
279+
280+ This information can be used to diagnose problems with how a CGI application is
281+ called.
282+
283+ To return to operation mode, remove or comment out the ` inspect ` subdirective.
284+
224285### Environment Variable Example
225286
226287In this example, the Caddyfile looks like this:
0 commit comments