1

I try to set 2 url working. The one is : http://X.X.X.X/portainer and the other one http://X.X.X.X/grafana. I have 2 server blocks but only one works correctly. I have 404 not found for the other. Here my nginx conf :

/etc/nginx/nginx.conf

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;
    tcp_nodelay on;
    keepalive_timeout 65;
    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;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-available/01-grafana.conf

upstream grafana-backend {
        server localhost:3000;
}

server {
        listen 80;
        server_name X.X.X.X;

        access_log /var/log/nginx/01-grafana-access.log;
        error_log /var/log/nginx/01-grafana-error.log;

        location /grafana/ {
                proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_pass              http://grafana-backend/;
        }
}

/etc/nginx/sites-available/02-portainer.conf

upstream portainer-backend {
            server localhost:9000;
    }
    
    server {
            listen 80;
            server_name X.X.X.X;
    
            access_log /var/log/nginx/02-portainer-access.log;
            error_log /var/log/nginx/02-portainer-error.log;
    
            location /portainer/ {
                    proxy_set_header        Host $host;
                    proxy_set_header        X-Real-IP $remote_addr;
                    proxy_pass              http://portainer-backend/;
            }
    }

2 Links are OK in sites-enabled. Each web space, http://X.X.X.X/portainer/ and http://X.X.X.X/grafana/ works perfectly when I disable one of them.

Anyone have an idea?

Thank you in advance,

Regards.

snooker9
  • 33
  • 8
  • It depends on what `X.X.X.X` means? If they are the same value, you have two duplicate `server` blocks and only one will be used. Check your error log. – Richard Smith Feb 26 '21 at 14:36
  • Yes, I confirme X.X.X.X it's the same IP. How to use something else? Should I write X.X.X.X/portainer and X.X.X.X/grafana or something else? – snooker9 Feb 26 '21 at 16:01
  • No. Both requests will be handled by the same `server` block. Place both `location` blocks within the same `server` block. See [how Nginx processes a request](http://nginx.org/en/docs/http/request_processing.html). – Richard Smith Feb 26 '21 at 16:06
  • Perfect! It works with only one server block, in one file .conf. Thank also for the link. – snooker9 Feb 26 '21 at 17:05

0 Answers0