0
Z odpowiedzią

Domain + subdomains in the same "website"?

Thibaut 6 lat temu Ostatnio zmodyfikowane przez Eugene Pankov (Project coordinator) 6 lat temu 12
Hey,

Does Ajenti support subdomains without the need to create separate websites, but use subfolders instead? I guess in this case each subdomain site would not create a separate php5-fpm instance. Is the reasoning correct? Does it make sense?

I quickly tried to make it work with "custom configuration" directives but, coming from Apache, I still have some issue with Nginx. :) So I prefer to ask, maybe Ajenti doesn't support this at all.

Thanks!

Odpowiedź

Odpowiedź
Z odpowiedzią
Totally possible:

if ($host = 'sub.domain.com') { rewrite / /subpath; }
Odpowiedź
Z odpowiedzią
Totally possible:

if ($host = 'sub.domain.com') { rewrite / /subpath; }
I tried that and it makes http://test.domain.com/ become http://test.domain.com/test/ :)

Instead, shouldn't it be a server block telling that the root is different, so the subdomain serves the content from a subfolder?
Did you paste the code as-is? Because, "If the replacement string begins with http:// then the client will be redirected" (nginx manual). You can also try to replace rewrite with a custom root/alias path.
Yes I pasted it as is.
Some progress. I've set this server block for the subdomain:

server {
    root /srv/domain.com/test;
    server_name test.domain.com;
}
The results:
  • HTML is OK
  • PHP at http://test.domain.com = 403 Forbidden
  • PHP at http://test.domain.com/index.php = the PHP is downloaded

So there is something wrong with PHP. I tried to add "index index.php" and things like that but the error remains. Any idea? :)
It's quite obvious - you made an empty static website pointing at a directory with .phps. Did you actually try to use a condition with alias setting inside instead of rewrite? You need to put that condition in the main website (which needs to be set up to listen at subdomain as well).
No it's a PHP FastCGI website... That's why I don't understand that PHP files are not served.
Look, you have put your PHP content entries in a main website, and now you created a separate website using custom configuration, without any dynamic content at all. Take a look at the generated .conf for better understanding. 
Mmm ok. You mean I need to create a second PHP FastCGI content with /test[^/]\.php(/|$) as URL pattern?
I mean that you need following in custom MAIN website config: 
if ($host = 'sub.domain.com') { root /sub/domain/path; }
Hey. I tried to add the code but I have this error:

nginx: [emerg] "root" directive is not allowed here in /etc/nginx/conf.d/(...)