Welcome! Log In Create A New Profile

Advanced

nginx, php7.0-fpm and laravel, not able to set it up when the url has a prefix which the server doesn't have

Posted by Plato Puthur 
Hello

I am trying to set up a laravel installation in docker with php-fpm and
nginx server on a separate container. The issue is the laravel is installed
in a path like /home/apps/foo and the url I need is abcd.com/v11/. I
thought this was fairly simple, but I am not able to set it up. Here is my
location part in the nginx config

location /v11/ {
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass php_wbv1.0:5000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
include fastcgi_params;
}
}

I tried rewrite tag, and tried giving alias inside the location block, both
didn't work. The thing is if I remove the /v11/ from the location tag and
the URL, its working without any issues.

What is the right way to do this?


--

Sincerely,
Plato P
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
> I tried rewrite tag, and tried giving alias inside the location block, both didn't work. The thing is if I remove the /v11/ from the location tag and the URL, its working without any issues What is the right way to do this?


The try_files needs probably be changed to:

try_files $uri $uri/ /v11/index.php?$query_string;


rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Hello,
Thanks for that input, I changed my config like you said and also set the
fastcgi_param SCRIPT_FILENAME to /path/to/the/index.php;

But I feel like this should be done by the rewrite directive instead of
this way. Now that this is working, can someone please tell me if I can use
the rewrite tag so that I can avoid hardcoding the path everywhere?

On Mon, Aug 6, 2018 at 1:31 PM, Reinis Rozitis <[email protected]> wrote:

> > I tried rewrite tag, and tried giving alias inside the location block,
> both didn't work. The thing is if I remove the /v11/ from the location tag
> and the URL, its working without any issues What is the right way to do
> this?
>
>
> The try_files needs probably be changed to:
>
> try_files $uri $uri/ /v11/index.php?$query_string;
>
>
> rr
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



--

Sincerely,
Plato P
about.me/plato_p
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
> Hello,
> Thanks for that input, I changed my config like you said and also set the fastcgi_param SCRIPT_FILENAME to /path/to/the/index.php;

> But I feel like this should be done by the rewrite directive instead of this way. Now that this is working, can someone please tell me if I can use the rewrite tag so that I can avoid
> hardcoding the path everywhere?


Well you didn't specify the actual rewrite.

Also from the initial mail the actual setup is a bit unclear - if the docker is only running php-fpm (and the nginx is on host) or both nginx and php are inside docker, but I assume it's the first.

As an idea - while you can mangle/rewrite the root/path in the nginx config, when configuring wordpress (+php-fpm) to run inside a docker container I found more easy just to set the container volume to have the same path (mount point) as the host server. So while isolated, both (nginx on host and php inside container) have identical directory tree.

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Hi,
Thanks for replying.
I have 3 containers, one with nginx, another 2 containers with php-fpm on
them. Both php-fpm are sharing a volume mounted from local system, but on
separate paths. The php-fpm container files are serving as api webservices.
Both are having different set of files, but the path is the same. ie, the
php files will be on this path: /home/apps/apis.

Now lets the the name of the containers are nginx_wb, php_wbv1.0, php_wbv1.1

If the nginx receives the request for http://abc.com/request_phonenumber
It forwards the requests to the php_wbv1.0 container with the url
http://abc.com/request_phonenumber

if the nginx receives the request for http://abc.com/v11/request_phonenumber
It forwards the request to the php_wbv1.1 container with the url
http://abc.com/request_phonenumber //Notice there is no v11 in the path.

This is what I wanted, although now its working fine, I wanted to use the
rewrite mechanism to do this, instead of hardcoding the SCRIPT_FILENAME.

Thanks.

On Tue, Aug 7, 2018 at 4:59 PM Reinis Rozitis <[email protected]> wrote:

> > Hello,
> > Thanks for that input, I changed my config like you said and also set
> the fastcgi_param SCRIPT_FILENAME to /path/to/the/index.php;
>
> > But I feel like this should be done by the rewrite directive instead of
> this way. Now that this is working, can someone please tell me if I can use
> the rewrite tag so that I can avoid
> > hardcoding the path everywhere?
>
>
> Well you didn't specify the actual rewrite.
>
> Also from the initial mail the actual setup is a bit unclear - if the
> docker is only running php-fpm (and the nginx is on host) or both nginx and
> php are inside docker, but I assume it's the first.
>
> As an idea - while you can mangle/rewrite the root/path in the nginx
> config, when configuring wordpress (+php-fpm) to run inside a docker
> container I found more easy just to set the container volume to have the
> same path (mount point) as the host server. So while isolated, both (nginx
> on host and php inside container) have identical directory tree.
>
> rr
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>


--

Sincerely,
Plato P
about.me/plato_p
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login