Yii In Nginx With Subdirectory Rather Than Domain Name

I’m trying to run yii under a web subdirectory, rather than as a domain in itself, i.e. instead of yiiapp.example.net, it should be example.net/yiiapp. Intent is to be able to serve multiple applications (rails as well as yii) from the same website, just using subdirectories to differentiate the apps.

I can get yii to run with the default nginx config documented in www.yiiframework.com/doc/guide/1.1/en/quickstart.apache-nginx-config. So with that now working, I tried a basic alias, i.e. instead of:


location / {

    ...

}



I changed it to:


location /yiiapp {

    alias /var/www/yiiframework/htdocs/$1;

    ...

}



the pages load and work, but I lose the stylesheets, images etc, which leads me to believe the alias is also affecting other parts of the path; this means either the web browser client cannot find the right paths to the resources, and/or I need more rewrite rules in the nginx configuration for this server.

I’ve tried following several examples that I managed to google, none are specific to yii but in more in general to just nginx. Some suggest alias as I’ve already done, others have more complicated rewrite rules which I’m not sure how they work.

Anybody have any suggestions or a working configuration that I could use? Thanks in advance.

(This is my first post, I can’t embed links so had to remove all the http references… so apologies!)

Nobody is using Nginx? I’m quite surprised.

nginx is quite popular with Yii in production, so no. The problem is that you’ve posted a nginx configuration problem in a Yii forum :)

I believe you abused the alias directive a bit. It’s not supposed to work that way. Can yo utry to use root instead? (And yes, I know).

:unsure: I’ve nginx working with other web applications, so I thought this was a Yii specific issue, perhaps some config with the url manager setup or other, which nginx folks wouldn’t be cluey about, hence my post here.

Most setups I’ve seens are just using subdomain, which is easy enough to setup (although I have some issue with chttpexceptions not being handled by Yii properly; that issue is in another post). But when using subdirectories, it tends to be a bit tricky (e.g. for owncloud I had a whole bunch of rewrites). So I thought posting here might be better…