Both @lucatacconi & @mwoodpatrick reported what appears to be the same
issue on GitHub. Namely that when using the PHP language module and
trying to access a URL that is a directory but without specifying the
trailing '/', they were getting a '503 Service Unavailable' error.
Note: This is when _not_ using the 'script' option.
E.g with the following config
{
"listeners": {
"[::1]:8080": {
"pass": "applications/php"
}
},
"applications": {
"php": {
"type": "php",
"root": "/var/tmp/unit-php"
}
}
}
and with a directory path of /var/tmp/unit-php/foo containing an
index.php, you would see the following
$ curl http://localhost/foo
<title>Error 503</title>
Error 503
However
$ curl http://localhost/foo/
would work and serve up the index.php
This commit fixes the above so you get the desired behaviour without
specifying the trailing '/' by doing the following
1] If the URL doesn't end in .php and doesn't have a trailing '/'
then check if the requested path is a directory.
2) If it is a directory then create a 301 re-direct pointing to it.
This matches the behaviour of the likes of nginx, Apache and
lighttpd.
This also matches the behaviour of the "share" action in Unit.
This doesn't effect the behaviour of the 'script' option which bypasses
the nxt_php_dynamic_request() function.
This also adds a couple of tests to test/test_php_application.py to
ensure this continues to work.
Closes: <https://github.com/nginx/unit/issues/717>
Closes: <https://github.com/nginx/unit/issues/753>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
|
|
/*
|
|
* Copyright (C) NGINX, Inc.
|
|
*/
|
|
|
|
#ifndef _NXT_UNIT_REQUEST_H_INCLUDED_
|
|
#define _NXT_UNIT_REQUEST_H_INCLUDED_
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "nxt_unit_sptr.h"
|
|
#include "nxt_unit_field.h"
|
|
|
|
#define NXT_UNIT_NONE_FIELD 0xFFFFFFFFU
|
|
|
|
struct nxt_unit_request_s {
|
|
uint8_t method_length;
|
|
uint8_t version_length;
|
|
uint8_t remote_length;
|
|
uint8_t local_addr_length;
|
|
uint8_t local_port_length;
|
|
uint8_t tls;
|
|
uint8_t websocket_handshake;
|
|
uint8_t app_target;
|
|
uint32_t server_name_length;
|
|
uint32_t target_length;
|
|
uint32_t path_length;
|
|
uint32_t query_length;
|
|
uint32_t fields_count;
|
|
|
|
uint32_t content_length_field;
|
|
uint32_t content_type_field;
|
|
uint32_t cookie_field;
|
|
uint32_t authorization_field;
|
|
|
|
uint64_t content_length;
|
|
|
|
nxt_unit_sptr_t method;
|
|
nxt_unit_sptr_t version;
|
|
nxt_unit_sptr_t remote;
|
|
nxt_unit_sptr_t local_addr;
|
|
nxt_unit_sptr_t local_port;
|
|
nxt_unit_sptr_t server_name;
|
|
nxt_unit_sptr_t target;
|
|
nxt_unit_sptr_t path;
|
|
nxt_unit_sptr_t query;
|
|
nxt_unit_sptr_t preread_content;
|
|
|
|
nxt_unit_field_t fields[];
|
|
};
|
|
|
|
|
|
#endif /* _NXT_UNIT_REQUEST_H_INCLUDED_ */
|
|
|