Nginx WebDAV: Direcory index is forbidden - nginx

I am trying for hours to get WebDAV to work on Nginx on Debian Buster. I have created a directory /var/www/html/webdav that is owned by www-data (user/group). I am using nginx-full, that includes http_dav_module and http-dav-ext. I have tried endless combinations of different directories in different locations with different rights but I always get the same error:
2019/09/24 14:12:47 [error] 3065#3065: *1 directory index of "/var/www/html/webdav/" is forbidden, client: 192.168.1.132, server: _, request: "GET /webdav/ HTTP/1.1", host: "192.168.1.219"
Here is my nginx configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /webdav/ {
client_body_temp_path /var/cache/nginx;
autoindex on;
autoindex_exact_size off;
auth_basic "restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
create_full_put_path on;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
dav_access group:rw all:r;
}
}
What am I doing wrong?

Related

Error 500 when using Alias and Rewrite nginx

I'm trying to use URL Rewrite with multiple directories in my Nginx but when I apply it I get an error 500.
server {
server_name mydns.com.br;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/godaddy-chained.crt ;
ssl_certificate_key /etc/nginx/ssl/server.key ;
root /var/www/manuais/index-site/;
location /folder1/ {
alias /var/www/manuais/folder1/;
rewrite /folder1/?(.*) /$1 break;
index index.html;
satisfy any;
allow myIP;
allow myIP;
deny all;
auth_basic "Auth";
auth_basic_user_file myAUTH;
}
location /folder2/ {
alias /var/www/manuais/folder2/;
rewrite /folder2/?(.*) /$1 break;
index index.html;
satisfy any;
allow myip;
allow myip;
deny all;
auth_basic "Auth";
auth_basic_user_file myAuth;
}
}
500 - Internal Server error
[alert] 2240016#2240016: *14432784 "alias" cannot be used in location "/folder1" where URI was rewritten, client: IP, server: mydns.com.br, request: "GET /folder1/ HTTP/1.1", host: "mmydns"
Is there any other way to rewrite this rule?

Nginx proxy_pass for /api/

I am currently deploying a ReactJS app to a Nginx server. The backend the application is located in a private network. I am currently using http://my-domain.com/ to access the frontend and from the frontend I access the backend using http://my-domain.com/api/. I am trying to configure Nginx to pass from http://my-domain.com/api/ to http://my-backend-loadbalancer.com/api/.
This is the configuration that I am running from `/etc/nginx/sites-available/my-domain.com
server {
listen 80;
listen [::]:80;
root /var/www/my-domain.com/html;
index index.html index.htm index.nginx-debian.html;
server_name www.my-domain.com my-domain.com;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_set_header Host my-backend-loadbalancer.com;
proxy_pass http://my-backend-loadbalancer.com$is_args$args;
}
}
I get a Bad Request error with this approach. I would like to know if I am following good practices in terms of accessing a backend within a private network and how can I make this work.
UPDATE
I have tried this configuration, but it seems that is not passing the arguments. Because when I try http://my-domain.com/api/ it redirects to http://my-backend-loadbalancer.com whit out any argument on it.
server {
listen 80;
listen [::]:80;
root /var/www/my-domain.com/html;
index index.html index.htm index.nginx-debian.html;
server_name www.my-domain.com my-domain.com;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://my-backend-loadbalancer.com;
}
}
Here's what I found in error.log.
2022/11/04 15:57:52 [error] 4749#4749: *3 no resolver defined to resolve internal-backend-213123123.us-west-1.elb.amazonaws.com, client: 10.0.0.78, server: www.my-domain.com, request: "GET /api/ HTTP/1.1", host: "my-domain.com", referrer: "http://my-domain.com/"

Not able to configure Nginx correctly as reverse proxy to both Jenkins and Nexus servers

I would like to have following Nginx urls by configuring Nginx as reverse proxy for both Jenkins and Nexus.
http://10.20.30.40 -> should display Nginx home page
http://10.20.30.40/jenkins -> should display Jenkins home page
http://10.20.30.40/nexus -> should display Nexus home page
After googling around I modified default configuration file and tried to check configuration. But I am getting following error while checking my configuration.
Note: I don't have any domain and ssl. Just using IP address for now.
sudo nginx -c /etc/nginx/nginx.conf -t
nginx: [emerg] invalid number of arguments in "proxy_pass" directive in /etc/nginx/sites-enabled/default:92
nginx: configuration file /etc/nginx/nginx.conf test failed
/etc/nginx/sites-available/default
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
# Jenkins server configuration
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
index index.html;
location /jenkins {
proxy_pass http://localhost:8080
try_files $uri $uri/ =404;
}
}
# Nexus server configuration
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
index index.html;
location /nexus {
proxy_pass http://localhost:8081
try_files $uri $uri/ =404;
}
}
Create two upstream block outside of server block, both for jenkins and nexus like this:
upstream backendjenkins {
server <hostname>:8080;
}
upstream backendnexus {
server <hostname>:8081;
}
Then, in the server block, mention like this:
location /jenkins {
proxy_pass http://backendjenkins;
try_files $uri $uri/ =404;
}
location /nexus {
proxy_pass http://backendnexus;
try_files $uri $uri/ =404;
}
Hope, this might help you.

Default redirect in the subfolder's root is not redirected to index.php

In the root directory, any redirect to localhost/ is simply redirected to index.php, but if you go inside the localhost/phone subdirectory, there's an index.php page too, and as you type localhost/phone/ you are not redirected to the index.php page. No idea why. This is my server configuration.
server {
listen 80;
listen [::]:80 default_server;
server_name localhost;
charset UTF-8;
index index.html index.php;
location / {
root xyz;
proxy_set_header Connection "";
if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; }
try_files $uri $uri/ $uri.html $uri.php?$args;
rewrite ^/(.*)/$ /$1 permanent;
location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|webp)$ {
expires 365d;
}
}
I tried to point the directory and added defaults for index.php and it works, but now all the url's inside /phone/ are showing blank.
location /phone {
index index.html index.php;
}
By "showing blank" means that they show a 404 error according to the error log
2019/05/08 23:40:58 [error] 26240#14076: *1 CreateFile()
"C:\xyz\nginx/xyz/phone/index" failed (2: The system cannot find
the file specified), client: ::1, server: localhost, request: "GET
/phone/index HTTP/1.1", host: "localhost"
Now the index.php shows a 404 error, what am I doing wrong? Even though the file is there
If you want to avoid a trailing / for all URIs, but still test for index.html and index.php, you should avoid using the index directive and the $uri/ term with the try_files directive.
One approach is to use a named location to test for PHP files. This location will need your fastcgi configuration.
For example:
root /path/to/root;
location / {
if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; }
rewrite ^/(.*)/$ /$1 permanent;
try_files $uri $uri.html $uri/index.html #php;
}
location #php {
try_files $uri.php $uri/index.php =404;
fastcgi_pass ...;
...
}

Add domain to Nginx config

here is my problem
I have domain "example.com" and i wanna that domain to be associated with folder /var/www/html/example.com
I've create file with name "example.com" in /etc/nginx/sites-available
server {
server_name http://example.com;
root /var/www/html/example.com;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
And here is my default file on /etc/nginx/sites-enabled
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 188.226.145.195;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /example.com/ {
try_files $uri $uri/ /example.com/index.php;
}
I know the problem is in that root /var/www/html but cant resolve it
Error log:
2016/02/27 13:53:53 [error] 10139#0: *11 directory index of "/var/www/html/" is forbidden, client: xxx.xx.xx.xx, server: 188.226.145.195, request: "GET / HTTP/1.1", host: "www.example.com"
Hope this is enough information so some1 can help.
Thanks.
I did it the problem was that i didn't give root to default location, when i do that works like a charm : )

Resources