Skip to content

Instantly share code, notes, and snippets.

@rafaga
Last active August 30, 2016 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaga/f035656553771ff5ba61078a52fc5a74 to your computer and use it in GitHub Desktop.
Save rafaga/f035656553771ff5ba61078a52fc5a74 to your computer and use it in GitHub Desktop.
Nginx PHP configuration with two diferent location to serve PHP files ( one with root privileges the other with userland privileges)
server {
listen 80;
server_name localhost;
rewrite_log on;
access_log /path/to/nginx/logs/default.access.log main;
access_log /path/to/nginx/logs/default.scripts.log scripts;
root /var/www/;
location ^~ /portal/v3 {
index index.php;
try_files $uri $uri/ /portal/v3/index.php;
location ~* \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9001;
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.php;
}
location / {
#root /var/www/;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
error_page 404 /404.html;
error_page 403 /403.html;
}
worker_processes 1;
error_log /path/to/nginx/logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format scripts '$document_root$fastcgi_script_name > $request';
access_log /path/to/nginx/logs/access.log main;
access_log /path/to/nginx/logs/scripts.log scripts;
sendfile on;
keepalive_timeout 65;
index index.html index.php;
include /path/to/nginx/sites-enabled/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment