2

I am very new to nginx. I get a 404 not found when I visit http://192.168.0.37/hls or when I visit http://192.168.0.37/hls/.

This is my /etc/nginx/nginx.conf file:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;


        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name _;

        root /var/www/html;
        index index.html;

        location /hls {
                root /var/www/html;
                index testtest.html;
            }
        }
}

There is nothing my /etc/nginx/sites-enabled/ directory. Both files /var/www/html/index.html and /var/www/html/testtest.html are owned by www-data and have 755 permissions.

Why can't I see the contents of /var/www/html/testtest.html when I visit http://192.168.0.37/hls or http://192.168.0.37/hls/?


However, I am able to see http://192.168.0.37/testtest.html

1 Answer 1

2

Nginx is looking for the file at /var/www/html/hls/testtest.html.

The path component of the URL is /hls/. The location /hls block is selected to process the request.

The index testtest.html; directive, converts the path component to /hls/testtest.html.

The root /var/www/html; directive converts this to a pathname by concatenating the root value with the path component - /var/www/html/hls/testtest.html


Alternatively, use the alias directive which subtracts the location value from the path component before resolving it into a pathname.

Either:

location /hls {
    alias /var/www/html;
    index testtest.html;
}

Or:

location /hls/ {
    alias /var/www/html/;
    index testtest.html;
}

Will look for /hls/testtest.html at /var/www/html/testtest.html. Note that for correct operation both the location and alias values should end with a / or neither end with a /.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .