Skip to content

Instantly share code, notes, and snippets.

@s1037989
Last active May 30, 2017 17:07
Show Gist options
  • Save s1037989/c913feefed20572a0b3b741392ade896 to your computer and use it in GitHub Desktop.
Save s1037989/c913feefed20572a0b3b741392ade896 to your computer and use it in GitHub Desktop.
nginx mojolicious php-fpm
This will allow you to run a php app behind an nginx reverse proxy on another server and serve the non-php static files with Mojolicious
http {
upstream php {
server 10.0.3.88:9000;
}
}
server {
listen 80;
server_name server;
access_log /var/log/nginx/server.log;
error_log /var/log/nginx/server.log;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/docroot/on/remote/php/server/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
}
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.3.88:8080;
proxy_set_header Host $http_host;
}
}
# sudo apt install php7.0-cli php7.0-cgi php7.0-fpm php7.0-xml
[www]
user = ubuntu
group = ubuntu
listen = 0.0.0.0:9000
listen.owner = www-data
listen.group = www-data
listen.allowed_clients = 127.0.0.1,10.0.3.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
ping.path = /ping
ping.response = pong
catch_workers_output = yes
#!/usr/bin/env perl
use Mojolicious::Lite;
hook before_dispatch => sub {
my $c = shift;
$c->app->static->paths([$c->app->home->child('public')]);
};
app->start;
mount '/path/to/docroot/on/remote/php/server.pl' => {
"Host" => qr{^server$},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment