Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure multiple laravel projects in one domain name in nginx

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to configure multiple laravel projects for one domain name in nginx. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

domain name

Suppose the domain name is: http://www.dev.com

Experimental environment

Ali Cloud ECS + centos + Nginx + php-fpm

Item 1

1. Project path: / data/wwwroot/project1/

two。 Access path: http://www.dev.com/project1/

Item 2

1. Project path: / data/wwwroot/project2/

two。 Access path: http://www.dev.com/project2/

Item 3

1. Project path: / data/wwwroot/project3/

two。 Access path: http://www.dev.com/project3/

Knowledge points involved

The location instruction of Nginx. For more information, please see https://www.jb51.net/article/154637.htm.

The alias instruction of Nginx. For more information, please see https://www.jb51.net/article/154640.htm.

Implementation steps

In order to implement the above access form, we need to use the location instruction and alias instruction in nginx, which are configured as follows

Location ^ ~ / ${PROJECT} / {alias {$PATH}; try_files $uri $uri/ @ ${PROJECT}; location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;}} location @ ${PROJECT} {rewrite / ${PROJECT} / (. *) $/ ${PROJECT} / index.php?/$1 last;}

Note: both ${PROJECT} and {$PATH} in the above configuration belong to the parts that need to be replaced in the actual process, where ${PROJECT} is the path part that url needs to access, such as project1, and {$PATH} represents the real access path of the project, such as / data/wwwroot/project1. Take http://www.dev.com/project1 access as an example, then the configuration of the corresponding Nginx is like this.

Location ^ ~ / project1/ {alias / data/wwwroot/project1/public; try_files $uri $uri/ @ project1; location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;}} location @ project1 {rewrite / project1/ (. *) $/ project1/index.php?/$1 last;}

For the configuration of project2 and project3, you only need to follow the above configuration template. Finally, the complete nginx configuration is as follows

Configuration starting with server {listen 80; server_name http://www.dev.com; access_log/ data/wwwlogs/nginx/access_log/www.dev.com_nginx.log combined; error_log/ data/wwwlogs/nginx/error_log/www.dev.com_errr_log; index index.html index.htm index.php; # project1 location ^ / project1/ {alias / data/wwwroot/project1/public; try_files $uri $uri/ @ project1 Location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;}} location @ project1 {rewrite / project1/ (. *) $/ project1/index.php?/$1 last;} # project2 starting configuration location ^ ~ / project2/ {alias / data/wwwroot/project2/public; try_files $uri $uri/ @ project2 Location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;}} location @ project2 {rewrite / project2/ (. *) $/ project2/index.php?/$1 last;} # project2 starting configuration location ^ ~ / project3/ {alias / data/wwwroot/project3/public; try_files $uri $uri/ @ project3 Location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;}} location @ project3 {rewrite / project3/ (. *) $/ project3/index.php?/$1 last;} # parse all .php location ~\ .php$ {fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php The link to fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params;} # pictures and videos, here is caching, caching for 30 days, do not write access log location ~. *\. (gif | jpg | jpeg | png | bmp | swf | mp4 | ico) ${expires 30d; access_log off;} # js css file configuration, here is caching, caching 7 days, do not write access log location. *\ (js | css)? ${expires 7d Access_log off;} location ~ /\ .ht {deny all;}} this is the end of the project on how to configure multiple laravel for one domain name in nginx. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report