Last active
March 16, 2023 11:17
-
-
Save mnshankar/9642844 to your computer and use it in GitHub Desktop.
Nginix config for hosting multiple laravel projects in sibling folders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Thanks
Thx.
this helps me to add new laravel project
server {
...
location /project2 {
index index.html index.php;
try_files $uri $uri /index.php?$args;
rewrite ^/project2 /(.*)$ /project2/index.php?$1 last;
}
...
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What if i have outside project outside webroot?
Seems like root and alias don't work. Can you confirm?