Newby at Nginx on Ubuntu. Main site is a WordPress site "example.com". No issue with this site. However, I need (cause someone did things in IIS and we need to move it to Nginx) to have a another site at "example.com/testsite" (not Wordpress, just static HTML).
Since this "testsite" was originally in IIS, sloppy coding was done and things are a complete mess of upper and lowercase.
So, I added a location block to my /ect/nginx/sites-enabled/example.com.conf
location /testsite {
alias /home/myusername/public_html/testsite;
index index.html;
}
This works! However as soon as a try to make this location case insensitve, I get a 404.
location ~* /testsite {
alias /home/myusername/public_html/testsite;
index index.html;
}
Ideas? Also, this site has tons of links that users can click on that are a mixture of upper/lower/proper and in no relation to the actual files that are on the server. Is there a way to make anything under that location block case insensitive (aka IIS way of doing it).
Thanks everyone.
Related
I am new to Webserver configurations etc.
My question is how can I write a rule for a root directory and all the content to that if someone tries directly a not authorised error appears.
eg in the picture prevent access to ajax and all thats contained
the config below will take care of this: (it is considered that the directory ajax is located in root directory you defined in your nginx config, otherwise you have to specify full address of your ajax directory relative to your root directory.)
location ~* /ajax/* {
return 403;
}
i just moved my server from apache to nginx, and my main site from joomla to wordpress (now it is a lot faster, but it cost me two months of learning nginx, and testing new configs etc.). Only problem that left is with new links structure.
Can somebody help me to rewrite old links to the new one?
This is mine links structure:
OLD> http://www.example.com/this-is-just-some-text-1234.html
NEW > https://www.example.com/this-is-just-some-text-09878
Main text in most cases stays the same, but post-id number is changed, and there is no .html at the end. http > https redirects are in nginx config already.
This can't really be done with nginx alone -- how would nginx have any idea what was the old ID with Joomla, and the new one with WordPress? It sounds like your transition process wasn't done correctly.
However, if you do have a list of old and corresponding new URLs, you can use the the map directive within nginx to supply such list.
map $uri $new_uri {
/this-is-just-some-text-1234.html /this-is-just-some-text-09878;
}
if ($new_uri) {
return 301 $new_uri;
}
References:
http://nginx.org/r/map
http://nginx.org/r/if
I'm building a system which uses dynamic DNS for user accounts, so you register for a sub domain.
I have a few server directives in place to catch things like api. and www. and other special cases, and I have a directive which reads the wildcard domain name and uses it to set a domain specific assets location.
server {
server_name "~^(?<domain>[a-z0-9]+)\.example\.com$";
root /sites/core;
location /assets {
alias /site-assets/$domain;
}
}
What I want to do is check for the existence of the assets directory and present, on the same domain, a different site.
To clarify, if the assets directory in the example above exists, serve one set of files, otherwise, serve another. Since the site I want to serve won't be IN the directory in question, I can't use try_files or anything like that.
I read all the horror stories about using the if directive but I think I need something like
if (-d /site-assets/$domain) {
... Do something
}
Then change the root, but that doesn't work.
Any ideas how I can achieve this?
OK. I figured this out. If there's a problem with it, let me know.
I have the following in a server directive
server {
server_name "~^(?<domain>[a-z0-9]+)\.example\.com$";
set $site core;
if (!-d /path/to/assets/$domain) {
set $site join;
}
root /path/to/sites/$site;
}
If the assets directory for the given domain name does NOT exist, then I can serve up a joining page for my site, which can pick up the domain name and allow the user to register. If it does exist, then serve up the main app.
This seems to me like a simple use of the if directive so shouldn't get me in too much trouble.
I am caching my websites pages into a static flat file cache and am trying to use a try_files directive to load the file first from cache if it exists and then go to web application.
I'm basically trying to do something like this:
try_files $uri $uri/ /var/www/vhosts/example.com/httpdocs/staticfilecache/$uri/index.html
In this example if the user requested example.com/products/ it would try staticfilecache/products/index.html The problem I have is that $uri already contains a trailing slash. Trying to use this with $uriindex.html creates an error.
Is there any performant/easy way to always strip the / but not rewrite the address in the browser?
What you are trying to do has many problems on many levels.
"/var/www/vhosts/$uri" is invalid. Except if you have duplicated
your whole document root under the staticfilecache folder.
Nginx has it's own caching system and will check it first by itself
without any intervention from you as long as it has been setup.
Nginx will check for index files by itself as long as the index directive has been set.
Your code is actually attempting to check the staticcache last and
not first as you said you wanted.
There is no point in creating a static file cache on disk. Nginx can
just as well read the static files from their original locations.
In any case, Nginx will create the cache for items that need cache,
usually dynamic files, by itself. It is not a manual job.
Basically, it looks like you are a bit on the wrong track on some webserver fundamentals.
The answer(strictly) to your question is,
rewrite ^(.*)/$ $1 break;
But I would recommend you don't do this and go through #Dayo's answer.
For some interesting stuff for caching guidance, you can check this out.
We're using Nginx on the server reserved for development (testing) and we want to prevent anyone outside the company from gaining access to the sites under development. However one of the sites uses online payment and for that a folder need to be accessible by anyone, used for the callback from the credit card company..
Is there any way we can protect an entire website but leave just one folder and all the files inside open ?
Regards,
Wael
server {
auth_basic "go away";
location /a {
auth_basic off;
}
}