Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-03-31 Thread Simone Bordet
Hi,

On Tue, Mar 31, 2020 at 9:34 PM Alexander Farber
 wrote:
> The above stuff works well, but now I am also trying to pass some 
> configuration information to the few PHP scripts I am also running - and 
> unfortunately this does not work - when I print($_ENV['COUNTRY'); in the PHP 
> scripts, the env. variable is not there.

This is not possible since they belong to 2 different processes.
The one that has the env variables set is a Java process (Jetty), the
one that runs PHP is php-fpm.

> Is there please a way to pass the env. vars from Jetty process to the PHP 
> scripts run through FastCGI?

This is currently not possible out of the box.

It is common, however, to pass FastCGI variables along with the
request, and these can be retrieved in PHP via e.g.
$_SERVER['COUNTRY'] or getenv('COUNTRY') but *not* $_ENV['COUNTRY'].

What we can do is to allow to configure init-param names in
FastCGIProxyServlet, and then we can read those names and forward them
to PHP.
Please file an issue at https://github.com/eclipse/jetty.project/issues.

Something like:


  envNames
  COUNTRY, DOMAIN, ...


and we call System.getenv("COUNTRY"), etc.

What you can do right now is to override this:

class FarberFCGIServlet extends FastCGIProxyServlet {
  protected void customizeFastCGIHeaders(Request proxyRequest,
HttpFields fastCGIHeaders) {
super.customizeFastCGIHeaders(proxyRequest, fastCGIHeaders);
fastCGIHeaders.put("COUNTRY", System.getenv("COUNTRY"));
...
  }
}

-- 
Simone Bordet

http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


[jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-03-31 Thread Alexander Farber
Hello and good evening,

on a CentOS Linux server I run 3 instances of Jetty on 3 different IP
addresses, serving a servlet and  Wordpress in 3 different languages:
English, German, Russian.

The Wordpress installations are configured exactly as described at
https://www.eclipse.org/jetty/documentation/current/configuring-fastcgi.html

And the Jetty instances are started by /etc/systemd/system/jetty-en.service
(and jetty-de.service at port 8081, jetty-ru.service at 8080):

[Unit]
Description=Jetty
After=network-online.target

[Service]
Environment=COUNTRY=en
Environment=DOMAIN=wordsbyfarber.com
Environment=DATABASE_URL=jdbc:postgresql://
127.0.0.1:6432/my_database_en?user=my_user_en=my_user_password
Environment=FCM_SECRET=
Environment=AMAZON_ID=
Environment=AMAZON_SECRET=
Environment=FACEBOOK_ID=
Environment=FACEBOOK_SECRET=
Type=simple
User=jetty
Group=jetty
ExecStart=/usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar
/usr/share/java/jetty-distribution-9.4.27.v20200227/start.jar
jetty.home=/usr/share/java/jetty-distribution-9.4.27.v20200227
jetty.base=/var/www/jetty-base-en jetty.http.host=127.0.0.1
jetty.http.port=8082
SuccessExitStatus=143
Restart=always
RestartSec=180
PrivateTmp=true

[Install]
WantedBy=multi-user.target

As you can see above I pass some information through the env. variables to
the custom Java servlet of my word game.

The above stuff works well, but now I am also trying to pass some
configuration information to the few PHP scripts I am also running - and
unfortunately this does not work - when I print($_ENV['COUNTRY'); in the
PHP scripts, the env. variable is not there.

Is there please a way to pass the env. vars from Jetty process to the PHP
scripts run through FastCGI?

The reason why I am asking is that I am trying to reuse as much source code
(Java, PHP, Javascript) while serving my word game in 3 different languages.

Thank you
Alex

PS: Below is my Jetty config xml file:

# cat /var/www/jetty-base-en/webapps/wordsbyfarber.com.xml


http://www.eclipse.org/jetty/configure_9_3.dtd;>



/var/www/html/wordsbyfarber.com


/





wordsbyfarber.com
www.wordsbyfarber.com





index.php
index.html




org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter
/*






files
$path /index.php?p=$path






default


org.eclipse.jetty.servlet.DefaultServlet



dirAllowed
false


gzip
true



/



org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet
*.php

proxyTo
http://localhost:9000


prefix
/


scriptRoot



scriptPattern
(.+?\\.php)



___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] How to include another web page in a page served by Jetty?

2020-03-31 Thread Alexander Farber
Thank you for your response Greg -


On Mon, Mar 30, 2020 at 10:09 AM Greg Wilkins  wrote:

>
> Jetty supports the Servlet API feature of RequestDispatcher.include, so
> one URI/resource can be included in another page.  The trick is how do you
> trigger than in the content that you are generating?From the servlet,
> it should be easy enough to get a RequestDispatcher and call it directly.
> If you want to do this from static content, then you will need to use
> something like JSP to process that content and allow dynamic components to
> be added.   For wordpress... either do it in wordpress... or do something
> very complex about intercepting responses and rewriting with the new
> content - possible but a lot of work.
>

then I will better use jQuery in my test server pages to fetch and insert
the web page content

Regards
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users