2016-11-04 41 views
13

嘗試用以下/etc/nginx/nginx.conf設置nginx的開始,當我得到一個unknown directive "perl_modules"錯誤:未知的指令「perl_modules」

user nginx; 
worker_processes 1; 

error_log /var/log/nginx/error.log warn; 
pid  /var/run/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    perl_modules perl/lib; 

    perl_set $subdomain_uppercase 'sub { 
     my $r = shift; 
     my $subdomain = $r->subdomain; 
     $subdomain = uc($subdomain); 
     return $subdomain; 
    }'; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    keepalive_timeout 65; 

    #gzip on; 

    include /etc/nginx/conf.d/*.conf; 
} 

我安裝的Perl:

[email protected]:/etc/nginx# perl -v 

This is perl 5, version 20, subversion 2 (v5.20.2) built for x86_64- linux-gnu-thread-multi 
(with 92 registered patches, see perl -V for more detail) 

,它看起來像模塊在我的nginx設置中啓用:

[email protected]:/etc/nginx# nginx -V 
nginx version: nginx/1.9.15 
built by gcc 4.9.2 (Debian 4.9.2-10) 
built with OpenSSL 1.0.1k 8 Jan 2015 
TLS SNI support enabled 
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=debian/extra/njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' 

值得注意的是,上面包括s --with-http_perl_module=dynamic

我是否缺少一個額外的步驟來啓用此perl模塊,以便我可以設置動態變量?

+0

您是如何安裝nginx的?告訴分佈式版本(debian?)和nginx包的來源。 –

回答

9

您安裝ngx_http_perl_module動態模塊(--with-http_perl_module=dynamic),所以你需要在你的nginx.conf的開始裝載該模塊:從您--modules-path選項

load_module /usr/lib/nginx/modules/ngx_http_perl_module.so 

我用路徑,所以請檢查此目錄以獲取http_perl模塊文件的確切名稱

+0

謝謝你,工作完美。我添加了以下內容以使其在我的'/ etc/nginx/nginx.conf'文件中工作:'''user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; load_module /usr/lib/nginx/modules/ngx_http_perl_module.so; 事件worker_connections 1024;在我的原始問題的上面例子中的'http {'塊之前'''''''''''' – PurrBiscuit