0

I'm working on a docker Nginx server on local, this is my conf.d/default.conf configuration:

server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;

    server_name localhost;

    ssl_certificate     /etc/ssl/certs/localhost.pem;
    ssl_certificate_key /etc/ssl/private/localhost.key;

    root /usr/share/nginx/html;

    index index.html index.htm;
 
    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        index index.html index.htm;
        autoindex on;
    }
}

This configuration works perfectly, but for last "location" block, which works as an "userDir" directive, I have to type an URL like this: https://localhost/~user1/

In order to remove that trailing slash, I tried:

location ~ ^/(.+?)(/.*)?$ { 
    alias /home/$1/public_html$2;
    index index.html index.htm; 
    autoindex on;       
}  

This solution works fine and answers with the index.html content in "/home/user1/public_html" by using the URL https:/localhost/user1 which is how I want it to work, but then, root content (https:/localhost/) becomes 404 Not Found.

Hope I did explain it well and someone has a solution! Thank you in advance!!

0 Answers0