See the below nginx configuration file.
Virtual name based hosting (example.com), passing requests for example.com and www.example com to the mono fastcgi-process on port 9000 (127.0.0.1:9000)
I've added the file google-site-verification, but the problem is, the asp.net fastcgi-application is a MVC application, so it doesn't find the controller called "google79af7e588a34905e0.html".
I'm trying to overwrite the location in the virtual host config file, so it doesn't forward the request for google79af7e588a34905e0.html to the fastcgi-application, but it doesn't work.
I've restarted nginx, but it doesn't make a difference...
What am I doing wrong ?
I've tried removing the equal-sign in "location = /" but that doesn't work, and I've tried moving the location overwrite before the main location, but that doesn't make a difference either.
I've also changed the hostname forth-and-back, just to see whether I'm in the right configuration file, and i am, when I change the domain name, i start getting 404.
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
server {
listen 80;
server_name www.example.com example.com;
access_log /var/log/nginx/your.domain1.xyz.access.log;
location / {
root /home/example/www/homepage;
#index index.html index.htm default.aspx Default.aspx;
#fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
#http://serverfault.com/questions/477103/how-do-i-verify-site-ownership-on-google-webmaster-tools-through-nginx-conf
location = /google79af7e588a34905e0.html {
rewrite ^/(.*) $1;
return 200 "google-site-verification: $uri";
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
location /shared_images {
root /usr/share;
autoindex off;
}
error_page 404 /CustomErrors/404.htm;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/www;
#}
}
A location above your root definition could do the trick
without any rewrite.
I would go for this kind of setup:
Here we use nginx
try_files
directive to check if the files exist physically in the filesystem. If files do not exist, then the request is passed to the MVC backend.I have also replaced
root
directives inside locations withalias
directives, because that makes the configuration more intuitive, at least I see it like that.This setup also makes nginx server all static assets, instead of making the MVC backend process those requests too. You might need to adjust your main
server
blockroot
directive.This setup needs the actual file on the filesystem though.