0

I want to place a text file into a folder to see if it can be accessed from the public via this url:

www.example.com/.well-known/acme-challenge/test.txt

Internally, the text file should be placed in this directory:

/var/www/certbot

This is my nginx configuration:

server {
    listen 80;

    server_name www.example.com;
    server_tokens off;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";

    error_log /var/log/nginx/sdr-fe-nginx-error.log info;
    access_log /var/log/nginx/sdr-fe-nginx-access.log;

    ignore_invalid_headers off;
    underscores_in_headers on;

    # Allow larger than normal headers
    large_client_header_buffers 4 64k;
    proxy_buffers         8 16k;  # Buffer pool = 8 buffers of 16k
    proxy_buffer_size     16k;    # 16k of buffers from pool used for headers
    

    location /.well-known/acme-challenge/ {
        allow all;
        root /var/www/certbot;
    } 
}

This is my declaration in my docker-compose file:

nginx:
    environment:
      - TZ=Asia/Singapore
    image: nginx:latest
    ports:
      - 80:80
      - "443:443"
    restart: unless-stopped
    networks: 
    - ${NETWORK}
    volumes:
      - ./:/etc/nginx/conf.d
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot

So far this only results in a 404 error when i access the url.

How can I properly make that /var/www/certbot folder public?

EDIT: My nginx does not generate any error logs in the specified log directory. The 404 error that shows up is an nginx error.

JianYA
  • 2,750
  • 8
  • 60
  • 136

2 Answers2

0

I think what you are looking for is alias not root. Just replace

root /var/www/certbot;

with

alias /var/www/certbot/;

Be careful about the trailing slash. It should be there. You can find more in here.

Andromeda
  • 1,205
  • 1
  • 14
  • 21
0

You need to remove the path before searching the root directory. Your location block should look something like this:

location /.well-known/acme-challenge {
    rewrite ^/\.well-known/acme-challenge(.*) $1 break;
    root /var/www/certbot;
} 
Mihai
  • 9,526
  • 2
  • 18
  • 40
  • Hi Mihai, thank you for answering. Is this a case of Nginx interfering with my paths? Does this mean if I want to declare more public folders, I’ll have to remove the path also? – JianYA Mar 20 '23 at 05:01
  • nginx is not interfering, he's just doing what it is instructed. Depending on your use case you can use root or alias (as suggested by @Andromeda). It's good to know them both. One more thing, you said there were no errors on nginx, but I could clearly see the error in `/var/log/nginx/sdr-fe-nginx-error.log` – Mihai Mar 20 '23 at 05:22
  • Hi Mihai, I tried searching in that directory but no file is generated. – JianYA Mar 20 '23 at 05:52
  • You need to actually make the http call that returns 404. then the log file will be generated. If it is not, then it is possible that nginx is not using the config that you posted so you will have to do more investigation. Also check the access logs since there you should see all the requests that do reach nginx. – Mihai Mar 20 '23 at 07:24