Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev ][Date Next ][Thread Prev ][Thread Next ][Date Index ][Thread Index ]
--conf-prefix=PATH
Прилагаемый патч добавляет возможность задать префикс для конфигурационных
файлов, применяемый обычно в дистрибутивах Линукса:
./configure --conf-prefix=/etc/nginx ...
Данные префикс используется для задания самого nginx.conf и в директивах
include, auth_basic_user_file, ssl-сертификатов. Для всего остального
используется --prefix=PATH.
Есть ли какие-нибудь замечания ?
--
Игорь Сысоев
http://sysoev.ru
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c (revision 529)
+++ src/http/ngx_http_core_module.c (working copy)
@@ -1226,7 +1226,8 @@
return NULL;
}
- if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path) == NGX_ERROR) {
+ if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0)== NGX_ERROR)
+ {
return NULL;
}
@@ -1915,7 +1916,7 @@
if (ngx_strcmp(value[0].data, "include") == 0) {
file = value[1];
- if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
+ if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
return NGX_CONF_ERROR;
}
@@ -2258,7 +2259,7 @@
conf->root.len = sizeof("html") - 1;
conf->root.data = (u_char *) "html";
- if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, &conf->root, 0) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
}
@@ -2695,7 +2696,7 @@
}
if (lcf->root.data[0] != '$') {
- if (ngx_conf_full_name(cf->cycle, &lcf->root) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
}
Index: src/http/ngx_http_variables.c
===================================================================
--- src/http/ngx_http_variables.c (revision 529)
+++ src/http/ngx_http_variables.c (working copy)
@@ -877,7 +877,9 @@
return NGX_ERROR;
}
- if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path) == NGX_ERROR)
{
+ if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0)
+ == NGX_ERROR)
+ {
return NGX_ERROR;
}
Index: src/http/modules/ngx_http_geo_module.c
===================================================================
--- src/http/modules/ngx_http_geo_module.c (revision 529)
+++ src/http/modules/ngx_http_geo_module.c (working copy)
@@ -198,7 +198,7 @@
if (ngx_strcmp(value[0].data, "include") == 0) {
file = value[1];
- if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
+ if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
return NGX_CONF_ERROR;
}
Index: src/http/modules/perl/ngx_http_perl_module.c
===================================================================
--- src/http/modules/perl/ngx_http_perl_module.c (revision 529)
+++ src/http/modules/perl/ngx_http_perl_module.c (working copy)
@@ -451,7 +451,7 @@
#endif
if (pmcf->modules.data) {
- if (ngx_conf_full_name(cf->cycle, &pmcf->modules) != NGX_OK) {
+ if (ngx_conf_full_name(cf->cycle, &pmcf->modules, 0) != NGX_OK) {
return NGX_CONF_ERROR;
}
}
Index: src/http/modules/ngx_http_auth_basic_module.c
===================================================================
--- src/http/modules/ngx_http_auth_basic_module.c (revision 529)
+++ src/http/modules/ngx_http_auth_basic_module.c (working copy)
@@ -352,7 +352,7 @@
}
if (conf->user_file.data) {
- if (ngx_conf_full_name(cf->cycle, &conf->user_file) != NGX_OK) {
+ if (ngx_conf_full_name(cf->cycle, &conf->user_file, 1) != NGX_OK) {
return NGX_CONF_ERROR;
}
Index: src/http/modules/ngx_http_map_module.c
===================================================================
--- src/http/modules/ngx_http_map_module.c (revision 529)
+++ src/http/modules/ngx_http_map_module.c (working copy)
@@ -375,7 +375,7 @@
if (ngx_strcmp(value[0].data, "include") == 0) {
file = value[1];
- if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
+ if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
return NGX_CONF_ERROR;
}
Index: src/event/ngx_event_openssl.c
===================================================================
--- src/event/ngx_event_openssl.c (revision 529)
+++ src/event/ngx_event_openssl.c (working copy)
@@ -198,7 +198,7 @@
ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
ngx_str_t *key)
{
- if (ngx_conf_full_name(cf->cycle, cert) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, cert, 1) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -211,7 +211,7 @@
return NGX_ERROR;
}
- if (ngx_conf_full_name(cf->cycle, key) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, key, 1) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -242,7 +242,7 @@
return NGX_OK;
}
- if (ngx_conf_full_name(cf->cycle, cert) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, cert, 1) == NGX_ERROR) {
return NGX_ERROR;
}
Index: src/core/ngx_conf_file.c
===================================================================
--- src/core/ngx_conf_file.c (revision 529)
+++ src/core/ngx_conf_file.c (working copy)
@@ -641,7 +641,7 @@
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
- if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
@@ -681,9 +681,10 @@
ngx_int_t
-ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
+ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix)
{
- u_char *p;
+ size_t len;
+ u_char *p, *prefix;
ngx_str_t old;
if (name->data[0] == '/') {
@@ -704,14 +705,22 @@
old = *name;
- name->len = cycle->root.len + old.len;
+ if (conf_prefix) {
+ len = sizeof(NGX_CONF_PREFIX) - 1;
+ prefix = (u_char *) NGX_CONF_PREFIX;
+ } else {
+ len = cycle->root.len;
+ prefix = cycle->root.data;
+ }
+
+ name->len = len + old.len;
name->data = ngx_palloc(cycle->pool, name->len + 1);
if (name->data == NULL) {
return NGX_ERROR;
}
- p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len),
+ p = ngx_cpymem(name->data, prefix, len);
ngx_cpystrn(p, old.data, old.len + 1);
return NGX_OK;
@@ -734,7 +743,7 @@
if (name) {
full = *name;
- if (ngx_conf_full_name(cycle, &full) == NGX_ERROR) {
+ if (ngx_conf_full_name(cycle, &full, 0) == NGX_ERROR) {
return NULL;
}
Index: src/core/ngx_conf_file.h
===================================================================
--- src/core/ngx_conf_file.h (revision 529)
+++ src/core/ngx_conf_file.h (working copy)
@@ -320,7 +320,8 @@
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
-ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name);
+ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name,
+ ngx_uint_t conf_prefix);
ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
void ngx_cdecl ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf,
ngx_err_t err, char *fmt, ...);
Index: src/core/nginx.c
===================================================================
--- src/core/nginx.c (revision 529)
+++ src/core/nginx.c (working copy)
@@ -653,7 +653,7 @@
cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
}
- if (ngx_conf_full_name(cycle, &cycle->conf_file) == NGX_ERROR) {
+ if (ngx_conf_full_name(cycle, &cycle->conf_file, 1) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -821,7 +821,7 @@
ccf->pid.data = (u_char *) NGX_PID_PATH;
}
- if (ngx_conf_full_name(cycle, &ccf->pid) == NGX_ERROR) {
+ if (ngx_conf_full_name(cycle, &ccf->pid, 0) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
@@ -841,7 +841,7 @@
ccf->lock_file.data = (u_char *) NGX_LOCK_PATH;
}
- if (ngx_conf_full_name(cycle, &ccf->lock_file) == NGX_ERROR) {
+ if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
Index: src/core/ngx_file.c
===================================================================
--- src/core/ngx_file.c (revision 529)
+++ src/core/ngx_file.c (working copy)
@@ -260,7 +260,7 @@
path->name.len--;
}
- if (ngx_conf_full_name(cf->cycle, &path->name) == NGX_ERROR) {
+ if (ngx_conf_full_name(cf->cycle, &path->name, 0) == NGX_ERROR) {
return NULL;
}
Index: src/core/ngx_log.c
===================================================================
--- src/core/ngx_log.c (revision 529)
+++ src/core/ngx_log.c (working copy)
@@ -333,7 +333,7 @@
} else {
cf->cycle->new_log->file->name = value[1];
- if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name)
+ if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0)
== NGX_ERROR)
{
return NGX_CONF_ERROR;
Index: src/core/ngx_file.h
===================================================================
--- src/core/ngx_file.h (revision 529)
+++ src/core/ngx_file.h (working copy)
@@ -108,7 +108,7 @@
curr->name.len = sizeof(path) - 1; curr->name.data = (u_char *) path; - if (ngx_conf_full_name(cf->cycle, &curr->name) == NGX_ERROR) { + if (ngx_conf_full_name(cf->cycle, &curr->name, 0) == NGX_ERROR) { return NGX_CONF_ERROR; } Index: auto/configure
===================================================================
--- auto/configure (revision 529)
+++ auto/configure (working copy)
@@ -67,6 +67,7 @@
have=NGX_PREFIX value="\"$NGX_PREFIX/\"" . auto/define
have=NGX_SBIN_PATH value="\"$NGX_SBIN_PATH\"" . auto/define
+have=NGX_CONF_PREFIX value="\"$NGX_CONF_PREFIX/\"" . auto/define
have=NGX_CONF_PATH value="\"$NGX_CONF_PATH\"" . auto/define
have=NGX_PID_PATH value="\"$NGX_PID_PATH\"" . auto/define
have=NGX_LOCK_PATH value="\"$NGX_LOCK_PATH\"" . auto/define
Index: auto/options
===================================================================
--- auto/options (revision 529)
+++ auto/options (working copy)
@@ -6,6 +6,7 @@
NGX_PREFIX=
NGX_SBIN_PATH=
+NGX_CONF_PREFIX=
NGX_CONF_PATH=
NGX_ERROR_LOG_PATH=
NGX_PID_PATH=
@@ -123,6 +124,7 @@
--prefix=*) NGX_PREFIX="$value" ;;
--sbin-path=*) NGX_SBIN_PATH="$value" ;;
+ --conf-prefix=*) NGX_CONF_PREFIX="$value" ;;
--conf-path=*) NGX_CONF_PATH="$value" ;;
--error-log-path=*) NGX_ERROR_LOG_PATH="$value";;
--pid-path=*) NGX_PID_PATH="$value" ;;
@@ -240,6 +242,7 @@
--prefix=PATH set the installation prefix
--sbin-path=PATH set path to the nginx binary file
+ --conf-prefix=PATH set the configuration prefix
--conf-path=PATH set path to the nginx.conf file
--error-log-path=PATH set path to the error log
--pid-path=PATH set path to nginx.pid file
@@ -360,6 +363,7 @@
NGX_PREFIX=${NGX_PREFIX:-/usr/local/nginx}
+NGX_CONF_PREFIX=${NGX_CONF_PREFIX:-$NGX_PREFIX}
case ".$NGX_SBIN_PATH" in
@@ -381,11 +385,11 @@
;;
.)
- NGX_CONF_PATH=$NGX_PREFIX/conf/nginx.conf
+ NGX_CONF_PATH=$NGX_CONF_PREFIX/conf/nginx.conf
;;
*)
- NGX_CONF_PATH=$NGX_PREFIX/$NGX_CONF_PATH
+ NGX_CONF_PATH=$NGX_CONF_PREFIX/$NGX_CONF_PATH
;;
esac
Index: auto/summary
===================================================================
--- auto/summary (revision 529)
+++ auto/summary (working copy)
@@ -148,6 +148,7 @@
cat << END
nginx path prefix: "$NGX_PREFIX"
nginx binary file: "$NGX_SBIN_PATH"
+ nginx configuration prefix: "$NGX_CONF_PREFIX"
nginx configuration file: "$NGX_CONF_PATH"
nginx pid file: "$NGX_PID_PATH"
END
Index: auto/install
===================================================================
--- auto/install (revision 529)
+++ auto/install (working copy)
@@ -26,20 +26,23 @@
test ! -f '$NGX_SBIN_PATH' || mv '$NGX_SBIN_PATH' '$NGX_SBIN_PATH.old'
cp $NGX_OBJS/nginx '$NGX_SBIN_PATH'
- test -d '`dirname "$NGX_CONF_PATH"`' - || mkdir -p '`dirname "$NGX_CONF_PATH"`'
+ test -d '$NGX_CONF_PREFIX' || mkdir -p '$NGX_CONF_PREFIX'
- cp conf/koi-win '`dirname "$NGX_CONF_PATH"`'
- cp conf/koi-utf '`dirname "$NGX_CONF_PATH"`'
- cp conf/win-utf '`dirname "$NGX_CONF_PATH"`'
+ cp conf/koi-win '$NGX_CONF_PREFIX'
+ cp conf/koi-utf '$NGX_CONF_PREFIX'
+ cp conf/win-utf '$NGX_CONF_PREFIX'
- test -f '`dirname "$NGX_CONF_PATH"`/mime.types' || - cp conf/mime.types '`dirname "$NGX_CONF_PATH"`/mime.types'
- cp conf/mime.types '`dirname "$NGX_CONF_PATH"`/mime.types.default'
+ test -f '$NGX_CONF_PREFIX/mime.types' + || cp conf/mime.types '$NGX_CONF_PREFIX'
+ cp conf/mime.types '$NGX_CONF_PATH/mime.types.default'
- test -f '$NGX_CONF_PATH' || cp conf/nginx.conf '$NGX_CONF_PATH'
- cp conf/nginx.conf '`dirname "$NGX_CONF_PATH"`/nginx.conf.default'
+ test -f '$NGX_CONF_PREFIX/fastcgi_params' + || cp conf/fastcgi_params '$NGX_CONF_PREFIX'
+ cp conf/fastcgi_params '$NGX_CONF_PATH/fastcgi_params.default'
+ test -f '$NGX_CONF_PATH' || cp conf/nginx.conf '$NGX_CONF_PREFIX'
+ cp conf/nginx.conf '$NGX_CONF_PREFIX/nginx.conf.default'
+
test -d '`dirname "$NGX_PID_PATH"`' || mkdir -p '`dirname "$NGX_PID_PATH"`'