umami icon indicating copy to clipboard operation
umami copied to clipboard

Improving Installation Documentation for Nginx and Systemctl Service

Open sylwesterdigital opened this issue 1 year ago • 3 comments

Describe the feature or enhancement

"Hi,

I attempted to install Umami on Ubuntu 20 using MySQL, with systemctl managing umami.service and Nginx acting as a proxy server. My goal is to access my Umami analytics at https://mydomain/analytics (domain name redacted).

Below is a segment of the Nginx domain configuration:

location ^~ /analytics/_next/static/ {
    alias /var/www/mydomain/analytics/umami/.next/static/;
    access_log off;
    expires max;
}

location /analytics {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

Here is the systemctl configuration for the service:

[Unit]
Description=Umami - A simple, fast, website analytics alternative
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/www/mydomain/analytics/umami
ExecStart=/usr/bin/node /var/www/mydomain/analytics/umami/.next/standalone/server.js
Restart=always
User=root

[Install]
WantedBy=multi-user.target

After completing the installation and build, I successfully logged in as admin to the panel at https://mydomain/anal and set up the website tracking. Then, I inserted the following tracking script into the website header:

<script async src="https://mydomain/analytics/script.js" data-website-id="0dc04f77-2b3b-44fd-881e-cf61ccdb2496"></script>

However, Nginx is unable to load the script.js from the specified location, resulting in a 404 (Not Found) error for analytics/script.js. Additionally, the Umami API at https://mydomain/anal/api is also missing.

What could I be missing?"

sylwesterdigital avatar Feb 25 '24 04:02 sylwesterdigital

I think you need proxy_pass http://127.0.0.1:3000/; not proxy_pass http://127.0.0.1:3000;. I believe right now it is proxying the request to Umami saying "Hey Umami, what's at /analytics/?" and Umami has no clue. But the extra slash makes nginx change the question to "Hey Umami, what's at /?"

Edit: FWIW this is my config for a subdomain installation:

server {
	include /etc/nginx/snippets/ssl/tracker.domain.com.conf;

	listen 443 quic; # HTTP3
	listen 443 ssl;
	#listen [::]:443 quic; # HTTP3
	#listen [::]:443 ssl;
	server_name tracker.domain.com;

	access_log /var/log/nginx/tracker.domain.com.access.log main;

	location / {
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Host $host;
		proxy_pass http://127.0.0.1:9016;
	}
}

jrjake avatar Mar 02 '24 04:03 jrjake

I ended up moving the tracker from a path to a subdomain but still had default issues with content from the Next.js "static" and "public" umami folders. Finally, I figured it out; here is my partially redacted Nginx config:

# Additional server block for analytics.mydomain.com
server {
    listen 443 ssl http2;
    server_name analytics.mydomain.com;
    ssl_certificate /etc/letsencrypt/live/analytics.mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/analytics.mydomain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~* ^/(script.js|favicon.ico|site.webmanifest|favicon-32x32.png|favicon-16x16.png|android-chrome-192x192.png|android-chrome-512x512.png|apple-touch-icon.png|browserconfi>
        root /var/www/mydomain/analytics/umami/public;
        try_files $uri $uri/ =404;
    }

    location /_next/static/ {
        alias /var/www/mydomain/analytics/umami/.next/static/;
        access_log off;
        expires max;
    }
}


sylwesterdigital avatar Mar 02 '24 11:03 sylwesterdigital

I wanted to add my working config here for anyone who had similar issues. This config worked with setting the BASE_PATH=/stats environment variable in my .env file before running yarn build.

        location /stats/_next/static/ {
                alias /opt/umami/.next/static/;
                access_log off;
                expires max;
        }
        location /stats {
                proxy_pass http://127.0.0.1:9898;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

nginx 1.18 umami 2.10.2 node 20.12.0

JordanParsons avatar Apr 02 '24 16:04 JordanParsons

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Jun 02 '24 01:06 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Jun 09 '24 01:06 github-actions[bot]