[英]Laravel in a subfolder on nginx server
I am trying to set up laravel in a subfolder ( laravel-project
) of a project.我正在尝试在
laravel-project
的子文件夹 ( laravel-project
) 中设置 laravel。 I somehow got the home page to work doing this in the config file: rewrite "/project/home.php" /laravel-project/public/index.php$1;
我以某种方式让主页在配置文件中执行此操作:
rewrite "/project/home.php" /laravel-project/public/index.php$1;
However I cannot figure out how to get the routing work.但是我不知道如何让路由工作。 I would like that any request containing
laravel-project
would be redirected to laravel-project/public/index.php
so that laravel can figure out which controller and which method are to be called.我希望任何包含
laravel-project
请求都将被重定向到laravel-project/public/index.php
以便 laravel 可以确定要调用哪个控制器和哪个方法。 I did this:我这样做了:
location /laravel-project {
root /home/www/virtual/mysite/laravel-project/public;
try_files $uri $uri/ /index.php?$query_string;
}
However, when I try to navigate to mysite/laravel-project
or mysite/laravel-project/contacts
the application never hits public/index.php
file in the laravel-project folder.但是,当我尝试导航到
mysite/laravel-project
或mysite/laravel-project/contacts
,应用程序永远不会命中 laravel-project 文件夹中的public/index.php
文件。
Hope the information given is enough.希望所提供的信息足够。 Please let me know if any further info is required, and thank you for helping!
如果需要任何进一步的信息,请告诉我,并感谢您的帮助!
I want to put some new updated tips, maybe it's helps somebody :我想提出一些新的更新提示,也许对某人有帮助:
If you want to put your laravel
project in a subfolder
on a server with ngnix-ubuntu 16-php.7.2
, so here is update ngnix config :如果你想把你的
laravel
项目放在带有ngnix-ubuntu 16-php.7.2
的服务器上的subfolder
,那么这里是更新 ngnix 配置:
1) your nested(subfolder) isn't inside your main folder 1)您的嵌套(子文件夹)不在您的主文件夹中
/var/www/main:
/var/www/nested:
then your config :然后你的配置:
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
2) your laravel-test folder (subfolder) inside your main : 2)您的主要文件夹中的laravel-test文件夹(子文件夹):
/var/www/main:
/var/www/main/nested:
then your config :然后你的配置:
location /laravel-test {
alias /var/www/main/laravel-test/public;
try_files $uri $uri/ @laravelTest;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @laravelTest {
rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}
I found a proper configuration for deploy laravel in sub-folder我在子文件夹中找到了用于部署 laravel 的正确配置
location /websocket {
alias /var/www/html/websocket/public;
try_files $uri $uri/ @websocket;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
location @websocket {
rewrite /websocket/(.*)$ /websocket/index.php?/$1 last;
}
# megadealer
location ^~ /megadealer {
alias /var/www/choppies/megadealer/public;
try_files $uri $uri/ @megadealer;
location ~ \.php {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/choppies/megadealer/public/index.php;
}
}
location @megadealer {
rewrite /megadealer/(.*)$ /megadealer/index.php?/$1 last;
}
# end megadealer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.