skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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;
    } 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search