What I want:
/ => /var/www/
/measurements /var/meassurements
what I get using "location":
/ => /var/www/
/measurements => /var/measurements/measurements
what am I doing wrong?
Config-snippet:
location / {
# root /usr/share/nginx/html;
root /var/www/;
index index.html index.htm;
}
location /measurements {
root /var/measurements/;
autoindex on;
}
the following should work:
location / {
# root /usr/share/nginx/html;
root /var/www/;
index index.html index.htm;
}
location /measurements/ {
root /var;
autoindex on;
}
the reason is that the path is made up out as root + $uri, so your were ending up looking for /var/measurements/measurements
Related
I have this in my nginx configuration:
server {
listen 443 ssl;
server_name t.example.net;
include ssl.conf;
location / {
return 403;
}
location ~ ^/(\w+) {
return 403;
location ~ ^/(\w+)$ {
root /data/t/$1;
try_files /index.html =404;
}
location ~ ^/(\w+)/(.*)$ {
root /data/t/$1;
try_files $2 =404;
}
}
include favicon.conf;
access_log /var/log/nginx/t.log;
error_log /var/log/nginx/t.error.log;
}
In /data/t/lipsum/index.html, there is a image, which is located in /data/t/lipsum/bender.jpg:
<img src="bender.jpg" alt="Bender">
When visited from https://t.example.net/lipsum/index.html, the picture is fine, but it breaks when visited from https://t.example.net/lipsum.
If I change the img tag to src="lipsum/bender.jpg", the behavior is reversed: https://t.example.net/lipsum is fine and https://t.example.net/lipsum/index.html breaks.
How can I let them both work, or keep people from visiting /index.html?
I tested the configuration below on my server, which correctly maps the following URLs:
https://t.example.net/ # 403 forbidden
https://t.example.net/index.html # 403 forbidden
https://t.example.net/lipsum # /data/t/lipsum/index.html
https://t.example.net/lipsum/ # /data/t/lipsum/index.html
https://t.example.net/lipsum/foo # /data/t/lipsum/foo/index.html
server {
...
# forbid root URI
location ~ ^/(index.html)?$ {
return 403;
}
# require first URI part: /$1
# optionally match everything after: /$1$2
location ~ ^/([^/]+)(.*)? {
root /data/t/$1;
try_files $2 $2/index.html =404;
}
}
i need help about my Nginx configuration file. I coded my html file. This is the config file:
server
{
listen 888;
server_name phpmyadmin;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
location ~ /tmp/ {
return 403;
}
#error_page 404 /404-error.html;
location ~ /*-error.html {
try_files $1-error.html #error;
internal;
}
location #error {
root /var/www/wwwroot/umutisik.com/error_docs;
}
Also sorry for my bad English, not my main language.
I have a website and every time when I try to access the page in a subfolder like 'myDomain.com/privacy-policy', nginx returns me a '401 Authorization Required'.
The website has the following folder structure:
-myDomain.com/
-index.html
-images/
-(images..)
-legal-disclosure/
-index.html
-css/
-(css files..)
-privacy-policy/
-index.html
-css/
-(css files..)
-template/
-templates.min.css
The corresponding nginx configuration:
server {
listen 80;
server_name myDomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name myDomain.com;
ssl_certificate /root/ssl-certs/myDomain.com_ssl_certificate.cer;
ssl_certificate_key /root/ssl-certs/_.myDomain.com_private_key.key;
location / {
root /var/www/html/myDomain.com;
index index.html;
}
location /privacy-policy {
root /var/www/html/myDomain.com/privacy-policy;
index index.html;
}
location /legal-disclosure {
root /var/www/html/myDomain.com/legal-disclosure;
index index.html;
}
}
Does anyone knows why?
I solved my problem! I ignored the subdomain 'www.' on my nginx configurations and my links within the website referenced all to 'www.mydomain.com/...'.
Just added two server blocks with 'www.myDomain.com' and redirect them.
Now it works! :D
I tried below nginx config:
server {
listen 80;
server_name mysite.com;
location / {
root /var/www
index index.html;
try_files $uri.html $uri #proxy;
access_log off;
}
...
}
But I couldn't access to my site with /. I can access to my site with /index or /index.html though.
How can I access to mysite with /?
I have a wildcard DNS entry so *.mydomain.tld is directed to my server.
I'm Using nginx
I have 2 conf files titled:
default
myconf.conf
My conf files look like this:
default:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /var/www/website;
index index.html index.htm;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
}
myconf.conf:
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;
root /home/me/www/website;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
# orig # server_name localhost;
server_name me.mydomain.tld;
access_log /home/me/logs/me.mydomain.tld.access.log;
error_log /home/me/logs/me.mydomain.tld.error.log warn;
location / {
try_files $uri $uri/ $uri.php?$args;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
When I browse to the domains as follows, these are the conf files that load up.
me.mydomain.tld loads up root directory defined in myconf.conf
mydomain.tld loads up root directory defined in default
anything.mydomain.tld loads up root directory defined in myconf.conf
What is going wrong that default is not being the catchall it should be?
anything.mydomain.tld should be loading the root directory in the default conf file.
In your default config file, you have to specify default_server on both listen lines; also, you need to remove the server_name line:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/website;
index index.html index.htm;
#server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
}
The underscore that you are using for the server_name is not actually a wild card (if that was your intent). From the nginx Server Names documentation:
There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name. Other invalid names like “--” and “!##” may equally be used.