From 44de078234160afc363df7f15ae60f634d1f1bb1 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Mon, 9 Jan 2017 21:54:06 +0000 Subject: [PATCH] Enable new portal with Nginx (#595) --- Makefile | 8 ++-- _example/etc/manager-nginx.conf | 2 + _example/etc/portal-nginx.conf | 11 +++-- e2e-tests/index.psgi | 3 ++ e2e-tests/nginx.conf | 4 +- fastcgi-server/man/llng-fastcgi-server.1p | 2 +- fastcgi-server/sbin/llng-fastcgi-server | 54 +++++++++++++--------- lemonldap-ng-portal/site/htdocs/index.psgi | 3 ++ 8 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 e2e-tests/index.psgi create mode 100644 lemonldap-ng-portal/site/htdocs/index.psgi diff --git a/Makefile b/Makefile index 15619b566..6cac6d8f8 100644 --- a/Makefile +++ b/Makefile @@ -385,7 +385,7 @@ prepare_test_server: SBINDIR=`pwd`/e2e-tests/conf/sbin \ INITDIR=`pwd`/e2e-tests/conf/init \ ETCDEFAULTDIR=`pwd`/e2e-tests/conf/def - @cp -f e2e-tests/index.fcgi e2e-tests/conf/index.fcgi + @cp -f e2e-tests/index.* e2e-tests/conf/ @cp e2e-tests/lmConf-1.js e2e-tests/lemonldap-ng.ini e2e-tests/env.conf e2e-tests/test-nginx.conf e2e-tests/conf/ @cp e2e-tests/form.html e2e-tests/conf/site @perl -i -pe 'BEGIN{$$p=`pwd`;chomp $$p}s#__pwd__#$$p#;s#__port__#$(TESTWEBSERVERPORT)#;s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#;' \ @@ -626,15 +626,15 @@ install_manager_site: install_conf_dir # Clean svn files @rm -rf $$(find ${RMANAGERSTATICDIR} $(RMANAGERPSGIDIR) \ $(RMANAGERTEMPLATESDIR) $(RCONFDIR) -type d -name .svn) - $(PERL) -i -pe 's#__MANAGERSTATICDIR__#$(MANAGERRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME) - $(PERL) -i -pe 's#__MANAGERTEMPLATESDIR__#$(MANAGERTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME) + @$(PERL) -i -pe 's#__MANAGERSTATICDIR__#$(MANAGERRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME) + @$(PERL) -i -pe 's#__MANAGERTEMPLATESDIR__#$(MANAGERTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME) install_portal_site: install_conf_dir # Portal install @install -v -d $(RPORTALDIR) $(RPORTALSTATICDIR) \ $(RPORTALDIR)/skins/ \ $(RCRONDIR) $(RCONFDIR) - @cp -pR -f $(SRCPORTALDIR)/site/htdocs/index.fcgi $(RPORTALDIR) + @cp -pR -f $(SRCPORTALDIR)/site/htdocs/index.* $(RPORTALDIR) @cp -pR -f $(SRCPORTALDIR)/site/htdocs/static/* $(RPORTALSTATICDIR) @tar -cf - -C ${SRCPORTALDIR}/site/templates/ $$(ls ${SRCPORTALDIR}/site/templates/) |tar -xf - -C $(RPORTALTEMPLATESDIR) @for f in `find $(RPORTALTEMPLATEDIR) -type f -name '*.tpl'`; do \ diff --git a/_example/etc/manager-nginx.conf b/_example/etc/manager-nginx.conf index f13aafe45..73667eb2b 100644 --- a/_example/etc/manager-nginx.conf +++ b/_example/etc/manager-nginx.conf @@ -12,6 +12,8 @@ server { fastcgi_pass unix:__FASTCGISOCKDIR__/llng-fastcgi.sock; fastcgi_param LLTYPE manager; fastcgi_param SCRIPT_NAME /manager.psgi; + fastcgi_split_path_info ^(.*\.psgi)(/.+)$; + fastcgi_param PATH_INFO $fastcgi_path_info; } location / { diff --git a/_example/etc/portal-nginx.conf b/_example/etc/portal-nginx.conf index 83dcd52e1..27980715d 100644 --- a/_example/etc/portal-nginx.conf +++ b/_example/etc/portal-nginx.conf @@ -10,13 +10,14 @@ server { location ~ \.psgi(?:$|/) { include /etc/nginx/fastcgi_params; fastcgi_pass unix:__FASTCGISOCKDIR__/llng-fastcgi.sock; - fastcgi_param LLTYPE cgi; + fastcgi_param LLTYPE psgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - set $sn $request_uri; - if ($sn ~ "^(.*)\?") { + set $sn $document_uri; + if ($sn ~ "^(.*\.psgi).*") { set $sn $1; } fastcgi_param SCRIPT_NAME $sn; + fastcgi_param SCRIPT_FILENAME $document_root$sn; fastcgi_split_path_info ^(.*\.psgi)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; } @@ -29,6 +30,10 @@ server { #add_header Strict-Transport-Security "15768000"; } + location /static/ { + alias __PORTALSTATICDIR__; + } + # SOAP functions for sessions management (disabled by default) location /index/adminSessions { deny all; diff --git a/e2e-tests/index.psgi b/e2e-tests/index.psgi new file mode 100644 index 000000000..91a0415cc --- /dev/null +++ b/e2e-tests/index.psgi @@ -0,0 +1,3 @@ +use Lemonldap::NG::Portal::Main; + +Lemonldap::NG::Portal::Main->run( {} ); diff --git a/e2e-tests/nginx.conf b/e2e-tests/nginx.conf index 945b3147f..c67546b9c 100644 --- a/e2e-tests/nginx.conf +++ b/e2e-tests/nginx.conf @@ -1,5 +1,7 @@ worker_processes auto; pid conf/nginx.pid; +load_module /usr/lib/nginx/modules/ndk_http_module.so; +load_module /usr/lib/nginx/modules/ngx_http_lua_module.so; events { worker_connections 768; @@ -15,7 +17,7 @@ http { types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; - error_log conf/nginx.log info; + error_log conf/nginx.log debug; gzip off; include conf/*nginx.conf; access_log conf/nginx.log lm_combined; diff --git a/fastcgi-server/man/llng-fastcgi-server.1p b/fastcgi-server/man/llng-fastcgi-server.1p index 7096d2833..e87ff9567 100644 --- a/fastcgi-server/man/llng-fastcgi-server.1p +++ b/fastcgi-server/man/llng-fastcgi-server.1p @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "llng-fastcgi-server 1" -.TH llng-fastcgi-server 1 "2017-01-05" "perl v5.24.1" "User Contributed Perl Documentation" +.TH llng-fastcgi-server 1 "2017-01-09" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/fastcgi-server/sbin/llng-fastcgi-server b/fastcgi-server/sbin/llng-fastcgi-server index 7a930e727..f161ea831 100644 --- a/fastcgi-server/sbin/llng-fastcgi-server +++ b/fastcgi-server/sbin/llng-fastcgi-server @@ -5,7 +5,7 @@ use strict; use warnings; use POSIX; use Getopt::Long; -use Lemonldap::NG::Handler::SharedConf; +use Lemonldap::NG::Handler::Main::Reload; our $VERSION = '2.0.0'; @@ -87,6 +87,14 @@ my %builder = ( return $_apps{$script}->(@_); }; }, + psgi => sub { + return sub { + my $script = $_[0]->{SCRIPT_FILENAME}; + return $_apps{$script}->(@_) if ( $_apps{$script} ); + $_apps{$script} = do $script; + return $_apps{$script}->(@_); + } + }, ); unless ($>) { @@ -104,15 +112,30 @@ my $app = sub { }; # Hook for customFunctions initialization -use Lemonldap::NG::Handler::API::PSGI::Server; -$Lemonldap::NG::Handler::API::mode = 'PSGI::Server'; -Lemonldap::NG::Handler::SharedConf->init(); +Lemonldap::NG::Handler::Main::Reload->onReload( + bless( {}, 'Lemonldap::NG::Handler::FastCGI::Loader' ), + 'loadCustomLogins' ); + +my $server = Plack::Runner->new(); +$server->parse_options( + '-s' => $engine, + '-E' => 'deployment', + '--pid' => $pidFile, + '--nproc' => $nproc, + '--socket' => $socket, + '--proc-title' => 'llng-fastcgi-server', + ( $foreground ? () : '--daemonize' ), + '--no-default-middleware', + %plackOptions, +); + +$server->run($app); + +package Lemonldap::NG::Handler::FastCGI::Loader; # Load configuration and look if custom handlers have been defined -{ - $Lemonldap::NG::Handler::API::mode = 'PSGI::Server'; - my $conf = Lemonldap::NG::Handler::SharedConf->checkConf() - or die "Unable to get configuration"; +sub loadCustomLogins { + my ( $obj, $conf ) = @_; foreach my $lltype ( keys %{ $conf->{nginxCustomHandlers} // {} } ) { my $v = $conf->{nginxCustomHandlers}->{$lltype}; if ( $v =~ m#[/\\\.]# ) { @@ -131,21 +154,6 @@ Lemonldap::NG::Handler::SharedConf->init(); }; } } - -my $server = Plack::Runner->new(); -$server->parse_options( - '-s' => $engine, - '-E' => 'deployment', - '--pid' => $pidFile, - '--nproc' => $nproc, - '--socket' => $socket, - '--proc-title' => 'llng-fastcgi-server', - ( $foreground ? () : '--daemonize' ), - '--no-default-middleware', - %plackOptions, -); - -$server->run($app); __END__ =head1 NAME diff --git a/lemonldap-ng-portal/site/htdocs/index.psgi b/lemonldap-ng-portal/site/htdocs/index.psgi new file mode 100644 index 000000000..bc4fc74e7 --- /dev/null +++ b/lemonldap-ng-portal/site/htdocs/index.psgi @@ -0,0 +1,3 @@ +use Lemonldap::NG::Portal::Main; + +Lemonldap::NG::Portal::Main->run({}); -- GitLab