Nginx php (#792)

* www/nginx: add PHP support to model and view
* www/nginx: bugfixes and a change I hope I won't regret
* www/nginx: FastCGI-Upstreams
* www/nginx: undo line breaks
This commit is contained in:
Fabian Franz BSc
2018-08-17 16:55:15 +02:00
committed by GitHub
parent ee082bbe3c
commit 0c88da788d
6 changed files with 51 additions and 9 deletions
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Request Denied</title>
<title>Not Found</title>
<meta name="generator" content="OPNsense" />
<meta name="language" content="en-US" />
<style>
@@ -59,7 +59,7 @@
<label>Upstream Servers</label>
<type>dropdown</type>
<style>selectpicker</style>
<help>Select an upstream to proxy to.</help>
<help>Select an upstream to proxy to or connect via FastCGI if chosen.</help>
</field>
<field>
<id>location.root</id>
@@ -103,4 +103,16 @@
<type>checkbox</type>
<help>Force encrypted connections.</help>
</field>
<field>
<id>location.php_enable</id>
<label>Pass Request To Local PHP Interpreter / Threat Upstream As FastCGI</label>
<type>checkbox</type>
<help>Only use this setting if you know what you are doing. If not, expect your machine to get compromised. Use this setting when you want to run a local PHP application or call an external upstream, if selected, via FastCGI. Example upstreams are PHP-FPM or Rails via FastCGI API.</help>
</field>
<field>
<id>location.php_override_scriptname</id>
<label>(PHP) Router Script</label>
<type>text</type>
<help>If you set this setting, all requests are sent to this script instead of the request path (URL). Not using this setting on a remote instance can be dangerous.</help>
</field>
</form>
@@ -248,6 +248,13 @@
<force_https type="TextField">
<Required>N</Required>
</force_https>
<php_enable type="BooleanField">
<Required>Y</Required>
<default>0</default>
</php_enable>
<php_override_scriptname type="TextField">
<Required>N</Required>
</php_override_scriptname>
</location>
<custom_policy type="ArrayField">
@@ -29,11 +29,6 @@ default_type application/octet-stream;
keepalive_timeout {{ OPNsense.Nginx.http.keepalive_timeout }};
{% endif %}
#add_header X-Frame-Options SAMEORIGIN;
#add_header X-Content-Type-Options nosniff;
#add_header X-XSS-Protection "1; mode=block";
#add_header Referrer-Policy "same-origin";
# TODO add when core is ready for allowing nginx to serve the web interface
# include nginx_web.conf;
@@ -84,6 +79,9 @@ server {
server_name {{ server.servername }};
charset {{ server.charset }};
access_log /var/log/nginx/{{ server.servername }}.access.log {{ server.access_log_format }};
{% if server.root is defined and server.root != '' %}
root "{{server.root}}";
{% endif %}
#include tls.conf;
error_page 404 /opnsense_error_404.html;
error_page 500 501 502 503 504 /opnsense_server_error.html;
@@ -55,7 +55,32 @@ location {{ location.matchtype }} {{ location.urlpattern }} {
auth_request /opnsense-auth-request;
{% endif %}
{% endif %}
{% if location.upstream is defined %}
{% if location.php_enable is defined and location.php_enable == '1' %}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param TLS-Cipher $ssl_cipher;
fastcgi_param TLS-Protocol $ssl_protocol;
fastcgi_param TLS-SNI-Host $ssl_server_name;
fastcgi_intercept_errors off;
{% if location.upstream is not defined %}
fastcgi_pass unix:/var/run/php-www.socket;
{% if location.php_override_scriptname is defined and location.php_override_scriptname != '' %}
fastcgi_param SCRIPT_FILENAME $document_root/{{ location.php_override_scriptname }};
{% else %}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
{% endif %}
{% else %}
fastcgi_pass upstream{{ location.upstream.replace('-','') }};
fastcgi_connect_timeout 10s;
{% if location.php_override_scriptname is defined and location.php_override_scriptname != '' %}
fastcgi_param SCRIPT_FILENAME {{ location.php_override_scriptname }};
{% else %}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
{% endif %}
{% endif %}
{% endif%}
{% if location.upstream is defined and (location.php_enable is not defined or location.php_enable != '1') %}
{% set upstream = helpers.getUUID(location.upstream) %}
proxy_pass http{% if upstream.tls_enable == '1' %}s{% endif %}://upstream{{ location.upstream.replace('-','') }};
{% if upstream.tls_enable == '1' %}
@@ -11,6 +11,6 @@ pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_value[error_log] = /var/log/fpm-php.webgui.log
php_admin_flag[log_errors] = on
{% endraw %}