I have the following files on my web server:
/var/www/html/--+
|
+-misc--+
| |
| +-misc1--+
| | |
| | +-index.html
| |
| +-misc2--+
| | |
| | +-index.php
| |
| +-misc3.php
|
+-wordpress--+
|
+-index.php
I have Nginx set up such that http://example.com/ goes to my Wordpress install. On my previous (Apache) setup I was able to easily create aliases to point to the items in misc
but I'm unsure how to do this in Nginx.
index index.php index.html;
root /var/www/html/wordpress;
location ~ [^/]\.php(/|$) {
limit_except GET POST {}
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_buffer_size 16k;
fastcgi_buffers 16 16k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SERVER_NAME $host;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(?:css|js|jpg|jpeg|gif|png|mp4)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location / {
try_files $uri $uri/ /index.php;
limit_except GET {}
}
What I'd like is:
- http://example.com/ loads /var/www/html/wordpress/index.php
- http://example.com/misc1 loads /var/www/html/misc/misc1/index.html
- http://example.com/misc2 loads /var/www/html/misc/misc2/index.php
- http://example.com/misc3.php loads /var/www/html/misc/misc3.php
What I've tried:
# http://example.com/misc1 shows index.html but anything else in the folder is 404
location /misc1 {
alias /var/www/html/misc/misc1;
}
# http://example.com/misc1 gives 403, http://example.com/misc1/index.html gives 404
location /misc1/ {
alias /var/www/html/misc/misc1;
}
# shows Wordpress 404 page
location /misc1/* {
alias /var/www/html/misc/misc1;
}
# gives 403 error
location ~ /misc1 {
alias /var/www/html/misc/misc1;
}
Nothing I've tried has had any effect on PHP, it does not work.
Not sure why you're using alias. Try this, it's not tested but it should get you at least closer to what you're trying to achieve. If it doesn't work comment with details on why it doesn't work, and show applicable logs and curls.
Edit Based on the comment "As soon as I change the root directive at the server scope, I get 404 on my Wordpress site, as though it's ignoring the root directive on the location scope." you could try this. I use this technique when I have a custom PHP app in the root directory with Wordpress in a subdirectory.
So as it turns out,
location
blocks based on regular expressions will always override otherlocation
blocks. My configuration had two regex locations: the block meant to enable caching on static resources, and the block meant to enable PHP. Since one of these blocks matched all the content being served, every other location block was being ignored!What I ended up doing is nesting location blocks, placing the static file and PHP blocks inside the location blocks. Now my config looks like this:
php.inc
static.inc
example.conf