1

My problem is following: I use Wordpress on Nginx with "pretty links". I also run 2 other services on ports 88 and 1234 and I want to make a subdomains bugs.mydomain and mail.mydomain. I did the proxypass on location / but it's working only for the main directory, anything that is after the domain/ is falling into Wordpress "pretty links" mechanism. Do you have any idea how to solve this? My config files below: The server config:

server {
    listen   <IP>:80;

    root /usr/share/nginx/www/domain;
    index index.html index.htm index.php;

    server_name domain www.domain;

    location / {
            try_files $uri $uri/ /index.html;
            if ( $host ~ "bugs.domain" ) {
                proxy_pass http://domain:88;
            }

            if ( $host ~ "mail.domain" ) {
                proxy_pass http://domain:1234;
            }
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            deny all;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    location ~ /\.ht {
            deny all;
    }

    include /home/domain/public_html/nginx.conf;
    }

the config for specified domain (with Wordpress):

#First there is many rewrites for the W3TC plugin, like minification, caches etc
if ($host ~* ^www\.(.*))
{
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
#
# unless the request is for a valid file, send to bootstrap
if (!-e $request_filename)
{
    rewrite ^(.+)$ /index.php?q=$1 last;
}

Now, when I enter domain:88 or domain:1234 it works. When I enter bugs.domain the website loads, but no CSS or images works as the url is bugs.domain/somapath and this falls into the Wordpress bootstrap. I run out of the ideas.

2 Answers 2

3

why create only 1 server with if's in it, separate the servers

server {
    listen 80;
    server_name bugs.example.com;
    proxy_pass http://example.com:88;
}
server {
    listen 80;
    server_name mail.example.com;
    proxy_pass http://example.com:1234;
}
server {
   listen 80;
   # the rest of your main server
   #
}
Sign up to request clarification or add additional context in comments.

2 Comments

That's probably good solution, thanks! However I just found what was the real problem, I will post it in few minutes
I don't think you meant to have colons in your directives? "server_name bugs.example.com" not "server_name: bugs.example.com"
1

So the problem was completely different then I thought. it was failing on this line:

try_files $uri $uri/ /index.html;

The problem was, that file index.html didn't exist, I only had index.php. Changing it solved the problem.

1 Comment

I think it's not a good idea to put the try_files before the if, It's more logical to put the if's first

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.