Pergunta

I would like to deploy lithium on nginx server, however there are configurations provided only for Apache and IIS. I've successfully written several nginx server configurations for various applications in past, but I'm struggling with this one.

Already asked this question on nginx and lithium forums, no luck.

This is best of what I've made so far.

root /var/servers/my_app/app/webroot;

location / {
    index index.php;
    try_files $uri $uri/ index.php;
}
location ~ \.php {
            fastcgi_pass unix:/tmp/php.socket;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /var/servers/my_app/$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
    }

Problem is on / (root page) every link gets index.php prepended, e.g. instead of

www.example.com/something

I get

www.example.com/index.php/something

Not sure if this even is nginx configuration related or rather something, that lithium does when it cannot detect Apache/IIS environment. Either way I cannot solve it.

Another thing, that when I access "www.example.com/test" (via direct URL input), the page renders correctly, however "www.example.com/test/" (with trailing slash) and "www.example.com/test/anything_here" is broken - all links gets appended to current URL e.g. pressing the same link creates this:

www.example.com/test/
www.example.com/test/test
www.example.com/test/test/test

EDIT: Updated configuration (Sorry for much delayed edit, but I'm still stuck and recently restarted solving this)

    root /var/server/my_app/app/webroot/;

    index index.php index.html;
    try_files $uri $uri/ /index.php?$args;

    location ~ \.php {
            fastcgi_pass unix:/tmp/php.socket;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /var/servers/my_app/$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
    }

    location ~/\.ht {
            deny all;
    }

}

As I mentioned in comments this now causes all links to have index.php included, it looks like:

www.example.com/index.php/something
www.example.com/index.php/stylesheet.css
Foi útil?

Solução 2

As I suspected the problem was that Lithium relies on some environment variables, in this case - link generation, it uses PHP_SELF, which happened to be incorrect.

Solution:

fastcgi_param PATH_INFO $fastcgi_path_info;

Instead of previously incorrect:

fastcgi_param PATH_INFO $fastcgi_script_name;

So final configuration:

root /var/server/my_app/app/webroot/;

index index.php index.html;
try_files $uri $uri/ /index.php?$args;

location ~ \.php {
        fastcgi_pass unix:/tmp/php.socket;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/servers/my_app$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
}

location ~/\.ht {
        deny all;
}

Thanks to rmarscher and mehlah @ lithum forums.

Outras dicas

I think your problem is that the try_files shouldn't be inside a location block.

Try the configuration shown here: http://li3.me/docs/manual/configuration/servers/nginx.wiki

I helped define it and have been using it locally and in production. It shouldn't cause any of the issues you're reporting.

Copying it below:

server {
        listen   IP_ADDRESS_HERE:80;
        server_name DOMAIN.COM;

        root   /var/www/DOMAIN.COM/webroot/;
        access_log /var/log/DOMAIN.com/access.log;
        error_log /var/log/DOMAIN.com/error.log warn;

        index  index.php index.html;

        try_files $uri $uri/ /index.php?$args;

        location ~ \.php$
        {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
        location ~ /\.ht {
                deny all;
        }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top