Forum: NGINX Serving wordpress from subdomain

2974d09ac2541e892966b762aad84943?d=identicon&s=25 adambenayoun (Guest)
on 2014-05-16 04:39
(Received via mailing list)
My setup is nginx + php-fpm. I am running a web application on
domain.com
and I am serving a wordpress configuration from domain.com/blog.

The problem is that the web app is served from /var/www/domain/html/http
and
wordpress is located outside of the root directory:
/var/www/domain/html/blog
How can I serve the blog effectively? I did try to symlink /blog from
within
the root but I feel this is a bad solution.

Here is my configuration file:

server {
        listen *:80;
        listen 443 ssl;
        server_name domain;
        error_log /var/www/domain/logs/error_log warn;
        ssl_certificate      /etc/nginx/certs/domain.crt;
        ssl_certificate_key  /etc/nginx/certs/domain.key;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5:!kEDH;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        root   /var/www/domain/html/http;
        index index.php;
        client_max_body_size 250m;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location /blog {
                root /var/www/domain/html;
                try_files $uri $uri/ /blog/index.php?q=$1;
        }
        location ~ \.php(/|$) {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param SERVER_NAME $http_host;
                fastcgi_pass 127.0.0.1:9000;
        }
        location ~* ^.+\.(ht|svn)$ {
            deny all;
        }

  # Static files location
        location ~*
^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
            expires max;
        }
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250139,250139#msg-250139
9ab56763e88f7be85aeca2d6cc5d25cb?d=identicon&s=25 Alan Chandler (Guest)
on 2014-05-16 07:12
(Received via mailing list)
On 16/05/14 03:38, adambenayoun wrote:
> My setup is nginx + php-fpm. I am running a web application on domain.com
> and I am serving a wordpress configuration from domain.com/blog.
>
> The problem is that the web app is served from /var/www/domain/html/http and
> wordpress is located outside of the root directory:
> /var/www/domain/html/blog
> ...
I have been wrestling with a similar problem - except mine is worse, in
that the applications running in a separate physical directory were php
applications which required $_SERVER['DOCUMENT_ROOT']  to point to the
actual physical directory for the real document root. I


>                  fastcgi_param PATH_INFO $fastcgi_script_name;
>                  fastcgi_param SERVER_NAME $http_host;
>                  fastcgi_pass 127.0.0.1:9000;

The problem here is that as nginx redirects to the second location block
when it can't find the file with try_files and goes to /blog/index.php,
it changes root back to the default

The way I solved the problem is

     location = /blog {
         rewrite ^ /blog/ permanent;
     }

     location /blog/ {
         alias /home/alan/dev/blog/web/;
         index index.php;
     }

     location ~ ^/blog/(.*\.php)$ {
         alias /home/alan/dev/blog/web/$1;
         include php-apps.conf;
     }

and the include file (used becaise I have several similar apps in this
area and each one is treated the same)

         include fastcgi_params;
         fastcgi_param DOCUMENT_ROOT /home/alan/dev/test-base;
         fastcgi_index index.php;
         fastcgi_intercept_errors on;
         fastcgi_pass unix:/var/run/php5-fpm-alan.sock;


There is a problem - which I don't really understand - that try_files
does not work with alias. so I am not using it in my sub location blocks

I do have

     location / {
         try_files $uri $uri/ =404;
     }

and with the whole thing in place I do get 404s when somebody attempts
to access a non existent page.  I think in your situation, your location
path equals the final elements of the physical filesystem path, so you
could use root instead of alias and then include the try_files bits you
have.


--
Alan Chandler
http://www.chandlerfamily.org.uk
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2014-05-18 10:51
(Received via mailing list)
On Thu, May 15, 2014 at 10:38:39PM -0400, adambenayoun wrote:

Hi there,

> My setup is nginx + php-fpm. I am running a web application on domain.com
> and I am serving a wordpress configuration from domain.com/blog.

For info: that's not a subdomain. It's frequently called "non-root" or
"sub directory".

If you expand your search to include those terms, do you find the config
you are looking for?

If you don't, can you provide:

* the request you make
* the response you get
* the response you want

for some requests that don't do what you want? It may make it clearer
which part is failing.

  f
--
Francis Daly        francis@daoine.org
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.