1

I have problem configuring laravel configuration that would run from /api/ segment of main domain. Idea is to serve at subdomain.domain.com main Angular aplication and in subdomain.domain.com/api/ laravel php server configuration.

UPDATE #1

I have managed to run laravel from /api/ segment with this configuration

server {
    listen 80;
    server_name subdomain.domain.com;
    root /var/www/subdomain.domain.com/client/monkey/dist;

    access_log /var/www/subdomain.domain.com.access.log;
    error_log  /var/www/subdomain.domain.com.error.log;
    rewrite_log on;

    index index.php index.html;

    location /  {

        root /var/www/subdomain.domain.com/client/monkey/dist;
        index index.html;
        if (!-e $request_filename){ # handles page reload
            rewrite ^(.*)$ /index.html break;
        }
    }

    location /api/ {
        root /var/www/subdomain.domain.com/server/;
        try_files $uri $uri/ /api/index.php$is_args$args;
    }

    location ~ /api/.+\.php$ {

        root /var/www/subdomain.domain.com/server/;
        rewrite ^/api/(.*)$  /$1  break;

        fastcgi_pass                    unix:/var/run/php5-fpm.sock;
        include                         /etc/nginx/fastcgi_params;
        fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index                   index.php;
        fastcgi_param                   MONKEY_ENV production;
        fastcgi_split_path_info         ^(.+?\.php)(/.*)?$;
        # fastcgi_split_path_info         ^(.+\.php)(.*)$;
    }
}

Only problem that has left is that when i'm using subdomain.domain.com/api/segment1/segment... then I need to add in routes.php

Route::group(['prefix' => 'api'], function () {
    // my routes settings
});

As laravel is starting from suddomain.domain.com/ as root path. How can i rewrite /api/ so that laravel takes /api/ as routing starting point ?

2
  • Are you using Laravel for anything outside /api? If not then why are you not making /api the public folder for Laravel? Commented Sep 16, 2014 at 14:30
  • /api path is only for laravel, cause this is my backend that laravel handles. So if i rename /server to /api it should work ? Do i need to remove any of rules in config or add extra rules ? Commented Sep 16, 2014 at 14:36

1 Answer 1

1

If I hava understanded your problem, I guess that you could solve this with the alias directive instead root. Using the root directive Nginx just takes de informed location and concat it at the end of the informed root path.

So, in your case, this conf:

location /api/ {
   root /var/www/subdomain.domain.com/server/;
   try_files $uri $uri/ /api/index.php$is_args$args;
}

nginx would resolved it to /var/www/subdomain.domain.com/server/api as the final path.

Using the alias directive, this conf,

location /api {
   alias /var/www/subdomain.domain.com/server/;
   try_files $uri $uri/ /api/index.php$is_args$args;
}

would be resolved to anything that's aim to '/api' but nginx is not concatening the 'api' string in the final path it uses.

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

Hopes this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.