I have a docker image with several containers (nginx, api, react, ...) and two server blocks inside nginx.conf
which gives me option to access via domain.com
and api.domain.com
.
Everything works so far, if I access via domain.com, it will point me to react container and port 3000. If I access via api.domain.com, it will point me to laravel app (php-fpm port 9000).
Now, I would like to "break" config to point me to laravel if I type domain.com/api
or domain.com/api/anything/here
, but to have react still working.
I almost got it, it will point me to laravel container (api container), but the problem is that it doesn't parse PHP correctly (remember that it works fine via api.doamin.com). I can see some laravel output, but in plain text.
This is what I have inside block for react (domain.com):
location /api {
alias /var/www/api/public/;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /var/www/api/public;
resolver 127.0.0.11;
set $api api;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass $api:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SERVER_NAME $host;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
# This part still works fine
location / {
index index.html;
root /var/www/app;
resolver 127.0.0.11;
set $reactjs reactjs;
proxy_pass http://$reactjs:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Best regards.