Skip to content

Instantly share code, notes, and snippets.

@srmklive
Created January 3, 2019 06:42
Show Gist options
  • Save srmklive/67d550cfac8bab530c69ef95a8b28d09 to your computer and use it in GitHub Desktop.
Save srmklive/67d550cfac8bab530c69ef95a8b28d09 to your computer and use it in GitHub Desktop.
Nginx Virtual Host Example with Directory Alias
server {
listen 80;
root /var/www/html;
index index.nginx-debian.html index.html index.htm index.php;
access_log off;
error_log /var/log/nginx/error.log error;
charset utf-8;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /auth {
alias /var/www/html/application/auth/public;
try_files $uri $uri/ @auth;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location @auth {
rewrite /auth/(.*)$ /auth/index.php?/$1 last;
}
location /backend {
alias /var/www/html/application/backend/public;
try_files $uri $uri/ @backend;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location @backend {
rewrite /backend/(.*)$ /backend/index.php?/$1 last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
sendfile off;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment