Download the PHP package csun-metalab/lumen-proxypass without Composer
On this page you can find all versions of the php package csun-metalab/lumen-proxypass. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download csun-metalab/lumen-proxypass
More information about csun-metalab/lumen-proxypass
Files in csun-metalab/lumen-proxypass
Package lumen-proxypass
Short Description Composer package for Lumen that resolves the correct absolute URLs when behind a proxy
License MIT
Informations about the package lumen-proxypass
Lumen Proxy Pass
Composer package for Lumen that resolves the correct absolute URLs when behind a proxy
This package is built for version 5.0 of Lumen and above. It modifies the functionality
of the url()
, asset()
, and other helper methods.
To install from Composer, use the following command:
Installation
First, add the following lines to your .env file to leverage the proxy attributes:
You may also add the following optional lines to your .env file to leverage the ability to FORCE the URL and schema without having to pass through a load balancer or proxy:
Next, register the service provider and the configuration file in bootstrap/app.php
as follows:
Configuration File
If you do not already have a config
directory in your project root, go ahead and create it.
In order to leverage the custom configuration values from this package, copy and paste the following code into a file called proxypass.php
within your config
directory in Lumen:
Environment Variables
The two environment variables you added to your .env file are the following:
PROXY_ACTIVE
Set this to true
to enable the proxying functionality or false
to disable it.
PROXY_PATH_HEADER
This is the PHP-interpreted value of the request header sent from your proxy. The
default is HTTP_X_FORWARDED_PATH
(the computed value of X-Forwarded-Path
)
Trusted Proxies
This package also has the ability to allow only certain proxy servers to modify the necessary values in order to set the proper absolute URL.
By default, all proxy servers are allowed to modify the values; if, however, the following value is set in your .env file then you can create a whitelist of proxies:
TRUSTED_PROXIES
This is a comma-delimited list of hostnames/IP addresses that are allowed to perform proxying functions.
The above example would allow the following three proxy servers to provide proxying functionality:
- 192.168.1.10 (would come from the
REMOTE_ADDR
value in PHP) - www.example.com (would come from the
X-Forwarded-Server
header from the web server) - 192.168.3.12 (would come from the
REMOTE_ADDR
value in PHP)
Usage Example
Let's say you have an API hosted at http://lumen.example.com
but that is
not the location you want to show to the world. Instead, you want to show a URL of
http://www.example.com/lumen
so you place your Lumen API behind a proxy.
However, you notice that while the front page loads properly, none of the URLs you
have written with the url()
, asset()
, or other helpers work with that URL and instead
continue writing http://lumen.example.com
as their base path.
You can configure your proxy to add a request header along with your ProxyPass
and
ProxyPassReverse
directives in Apache (ensure you have mod_headers
enabled and
mod_proxy
enabled as well):
Now all of your URLs using the url()
, asset()
, and other helpers will be written
correctly!