Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginix config for hosting multiple laravel projects in sibling folders.
server {
listen 80;
root /vagrant;
index index.html index.htm index.php app.php app_dev.php;
# Make site accessible from http://set-ip-address.xip.io
server_name 192.168.33.10.xip.io;
access_log /var/log/nginx/vagrant.com-access.log;
error_log /var/log/nginx/vagrant.com-error.log error;
charset utf-8;
# handle static files within project.. break at end to avoid recursive redirect
location ~project(\d*)/((.*)\.(?:css|cur|js|jpg|jpeg|gif|htc|ico|png|html|xml))$ {
rewrite project(\d*)/((.*)\.(?:css|cur|js|jpg|jpeg|gif|htc|ico|png|html|xml))$ /project$1/public/$2 break;
}
#project1 and project2 are two laravel projects that you want to serve
# at http://192.168.33.10.xip.io/project1/ and http://192.168.33.10.xip.io/project2/ respectively
location /project1{
rewrite ^/project1/(.*)$ /project1/public/index.php?$1 last;
}
location /project2 {
rewrite ^/project2/(.*)$ /project2/public/index.php?$1 last;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
# pass the PHP scripts to php5-fpm
# Note: \.php$ is susceptible to file upload attacks
# Consider using: "location ~ ^/(index|app|app_dev|config)\.php(/|$) {"
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
############# IMPORTANT - This section adjusts the request URI sent to laravel #################
set $laravel_uri $request_uri;
if ($laravel_uri ~ project(\d*)(/?.*)$) {
set $laravel_uri $2;
}
###################### Note request uri mod below ##############################################
fastcgi_param REQUEST_URI $laravel_uri;
fastcgi_param LARA_ENV local; # Environment variable for Laravel
fastcgi_param HTTPS off;
}
# Deny .htaccess file access
location ~ /\.ht {
deny all;
}
}
@z2z

This comment has been minimized.

Copy link

z2z commented Dec 26, 2014

What if i have outside project outside webroot?

Seems like root and alias don't work. Can you confirm?

@Izzur

This comment has been minimized.

Copy link

Izzur commented Apr 26, 2018

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.