nginx serve file but not all files in dynamic directory - nginx

i want to serve file on nginx server here's the case below
serve location /home/ubuntu/username/fileName
eg1 /home/ubuntu/john/d1.txt
eg2 /home/ubuntu/john/d2.txt
eg3 /home/ubuntu/kiddo/d3.txt
it is not accessable using.
location ~ /home/ubuntu/(?<user>.+)/(?<file>.+)$ {
root /home/ubuntu/$user/$file;
}
nginx rules on stackoverflow

Could you please try following, based on your shown samples. Please make sure to clear your browser cache before testing your URLs.
location ~ /home/ubuntu/([^/]*)/([^/]*)/?$ {
root /home/ubuntu/$1/$2;
}

Related

NGINX CSS Not Loading

I just set up my new vps to hold my website server. It works perfectly fine on my existing vps, but after I put it on the new one, none of the CSS files are loading.
Image here:
Any help is appreciated thanks!
In your server block in there has to be location for static files:
server {
server_name yourhost.com www.yourhost.com;
root /var/www/vhosts/yourhost.com/public/;
...
location /static {
alias /var/www/vhosts/yourhost.com/public/static;
}
}
So that
location /static {
alias /var/www/vhosts/yourhost.com/public/static;
}
has to be properly configured, pointing to the location where your static files are placed.
Then if your css is in file styles.css (or any other file) and is placed on the server as /var/www/vhosts/yourhost.com/public/static/css/styles.css, it will be accessible from /static/css/styles.css in your html.
To see where exactly this is configured, you can start with nginx.conf (normally in /etc/nginx/nginx.conf) and check what other conf files are imported.
Note the path provided is fully up to you, but once it's known it has to be properly configured with the alias in the static location.

How to serve file under root path using Nginx?

I have a website laike9m.com, which is served by Nginx. I want to access a text file AAA.txt with url laike9m.com/AAA.txt. The text file is on my server, let's say it's $HOME/AAA.txt. Redirection is not allowed. Current Nginx conf file is here. Thank you.
location ~ ^(.*\.txt)$ {
alias /home/laike9m/$1;
}
Solved it.

Nginx - how to correctly define root dir for location?

all.
Plese advice, how to correctly set root dir for location.
Now I have incorrect config:
location ~* ^/upload/
{
root /home/site/upload/
}
I want to locate all files from URLs, what are started from /upload/ from directory /home/site/upload/
But Nginx try to locate files from /home/site/upload/upload/ , for example /home/site/upload/upload/1.doc
How to fix my config?
Founded solution!
http://nginx.org/ru/docs/http/ngx_http_core_module.html#alias
Result:
location /upload/
{
alias /home/site/upload/;
}

configuring nginx server to store the static images and html

I want to configure the nginx server in my windows7 PC.For storing images and html files.
I followed up the following steps:
1.I downloaded the nginx-1.2.9 and unziped into c:\ filder.
2. created one folder "data" and within 'data" folder created another two folders say "WWW" and "images".
3.Keeping all images in the "images"folder .and .html file in folder "WWW".
4.Now started the nginx server using command C:\nginx-1.2.9>start nginx
5.Made changes in nginx.conf file.`
#server {
#location / {
# proxy_pass http://127.0.0.0:8080;
#}
#location /images/ {
# root /C:/data/images;
# }
}
Not able to access images and html page.
Please help me to solving this problem. I'm sure doing mistake in config file only..
Thanks in Advance,
Satya
You have commented the configuration data.First remove all the # from your configuration file.Then use the below code inside the server {}
location / {
root data/www;
}
location /images/ {
root data;
}
Note- the location of the static file inside your nginx root folder should be the (root+location) data and the access of the file should be "location" data. e.g from the first location configuration the static file should present inside the folder "data/WWW/" and in the second location configuration the static file should present inside the folder "data/images/".
URL folder inside nginx home path
----- --------------------------
localhost/hello.html data/WWW/hello.html
localhost/images/img1.png data/images/img1.png

How to disable Nginx index directory to only allow MaxCDN / NetDNA CDN?

I have a very large CDN purge server. It is structured like so
site.com/
site.com/assets/
site.com/assets/products/3424/imgs/large.jpg
site.com/assets/products/3424/imgs/med.jpg
site.com/assets/products/3424/imgs/small.jpg
site.com/assets/products/3424/xml/xml.xml
site.com/assets/products/3424/swf/swfvideo.jpg
site.com/assets/products/3424/html5/video.ogg
site.com/assets/products/3424/mp3/mp3.jpg
and so on.. there are large directories. I was wondering if I can disable ALL access to the directory listings /assets/, /products/, /3424/ - so basically the only people that can see the directories are the CDN purge bot. I want the CDN to be able to cache all the index folders and directories. Users would see forbidden on the directory but obviously they can see files..
I believe this can be accomplished by simply adding lines similar to this in the virtual server's config file:
server {
listen 80; # look familiar?
...
# something similar to this
if ($remote_addr != cdnIP) {
location /assets {
deny all;
}
}
}
Check out the configuration wiki on nginx's site for more about syntax and working with the config files to get them just how you want them.

Resources