I have a Nginx vhost look like:
server {
listen 80;
root /var/www/mywebsite.com/www; # my index is not a wordpress
index index.php index.html index.htm;
charset UTF-8;
server_name mywebsite.com;
location ^/(alias1|alias2)/(.*)$ { # my wordpress web site
# i want 2 alias for the same wordpress
alias /var/www/mywebsite.com/wordpress;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
When i call my web site from http://mywebsite.com/alias1
The php returned is from /var/www/mywebsite.com/www/index.php
if i put my root like /var/www/mywebsite.com/wordpress so the php is returned from /var/www/mywebsite.com/wordpress/index.php but the static return 404.
A part of my debug log:
2014/06/15 01:33:16 [debug] 3955#0: *3 using configuration "^/(alias1|alias2)"
2014/06/15 01:33:16 [debug] 3955#0: *3 http cl:-1 max:1048576
2014/06/15 01:33:16 [debug] 3955#0: *3 rewrite phase: 3
2014/06/15 01:33:16 [debug] 3955#0: *3 post rewrite phase: 4
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 5
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 6
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 7
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 8
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 9
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 10
2014/06/15 01:33:16 [debug] 3955#0: *3 post access phase: 11
2014/06/15 01:33:16 [debug] 3955#0: *3 try files phase: 12
2014/06/15 01:33:16 [debug] 3955#0: *3 http script copy: "/var/www/mywebsite.com/public_html"
2014/06/15 01:33:16 [debug] 3955#0: *3 http script var: "/alias1/"
2014/06/15 01:33:16 [debug] 3955#0: *3 trying to use file: "/alias1/" "/var/www/mywebsite.com/public_html/alias1/"
2014/06/15 01:33:16 [debug] 3955#0: *3 http script var: "/alias1/"
2014/06/15 01:33:16 [debug] 3955#0: *3 trying to use dir: "/alias1/" "/var/www/mywebsite.com/public_html/alias1/"
2014/06/15 01:33:16 [debug] 3955#0: *3 http script copy: "/index.php?q="
2014/06/15 01:33:16 [debug] 3955#0: *3 http script var: "/alias1/"
2014/06/15 01:33:16 [debug] 3955#0: *3 http script copy: "&"
2014/06/15 01:33:16 [debug] 3955#0: *3 trying to use file: "/index.php?q=/alias1/&" "/var/www/mywebsite.com/public_html/index.php?q=/alias1/&"
2014/06/15 01:33:16 [debug] 3955#0: *3 internal redirect: "/index.php?q=/alias1/&"
2014/06/15 01:33:16 [debug] 3955#0: *3 rewrite phase: 1
2014/06/15 01:33:16 [debug] 3955#0: *3 test location: ~ "^/(alias1|alias2)"
2014/06/15 01:33:16 [debug] 3955#0: *3 test location: ~ "\.php$"
2014/06/15 01:33:16 [debug] 3955#0: *3 using configuration "\.php$"
2014/06/15 01:33:16 [debug] 3955#0: *3 http cl:-1 max:1048576
2014/06/15 01:33:16 [debug] 3955#0: *3 rewrite phase: 3
2014/06/15 01:33:16 [debug] 3955#0: *3 post rewrite phase: 4
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 5
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 6
2014/06/15 01:33:16 [debug] 3955#0: *3 generic phase: 7
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 8
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 9
2014/06/15 01:33:16 [debug] 3955#0: *3 access phase: 10
2014/06/15 01:33:16 [debug] 3955#0: *3 post access phase: 11
2014/06/15 01:33:16 [debug] 3955#0: *3 try files phase: 12
2014/06/15 01:33:16 [debug] 3955#0: *3 http script var: "/index.php"
2014/06/15 01:33:16 [debug] 3955#0: *3 trying to use file: "/index.php" "/var/www/mywebsite.com/www/index.php"
2014/06/15 01:33:16 [debug] 3955#0: *3 try file uri: "/index.php"
Like you see, once nginx find the right path but after he What did I forget to do?
So if anybody have the solution i want a standart php website to target to a path: /var/www/mywebsite/www
And for the same domain i want an alias who target to a wordpress script path: /var/www/mywebsite/wordpress
So, I write a new question, more clearly here: Nginx vhost website + wordpress alias in subfolder
location ~* ^/(alias1|alias2)/(.*)$
, since it's a regular expression. – Deadooshkalocation ~* ^/(alias1|alias2) { ... }
– Deadooshkalocation ~* ^/(?:alias1|alias2)(/.*)?$ { alias /var/www/mywebsite.com/wordpress$1; }
nginx.org/en/docs/http/ngx_http_core_module.html#alias – Deadooshka