Next ImageOptimization Problem; Don't get the images
Unanswered
Milkfish posted this in #help-forum
MilkfishOP
Hello Everyone,
A few days ago, I completed the NextJs course, and I successfully deployed it on Vercel, which has me really excited. So, I decided to set up the same app on my personal server (it's a modest and old PC) running Ubuntu Server 24, using a Cloudflare tunnel to make it accessible through a Cloudflare domain (since I don't want to pay for a public IP), and Nginx as a proxy server redirecting to the application on localhost:3000.
However, I'm encountering the error: Illegal Instruction (core dumped).
After a lot of trial and error, I discovered that the issue is related to the Image component (next/image). When it tries to optimize the image, it throws an error, causing the application to crash. I'm not entirely sure why this happens, but if I set the directive unoptimized: true in next.config, it works perfectly. So, I believe the problem lies with the image optimizer.
I've tried numerous things (inspired by Microsoft Copilot), such as setting the user to www-data (or was it data-www, I can't recall exactly), checking file permissions (some are 755 and others are 644).
Configurations in Nginx to alias _next/image to / .next/media result in permission denied errors in the Nginx error log. I'd like to know if there's something I haven't considered about the image optimization processes or settings in NextJs.
I should clarify that I could use unoptimized: true, and the <img> tags get a normal path like /hero-desktop.png, which works and not the /_next/image?url=etcetcetc . But I want to know if there's something I haven't considered to make NextJs's image optimization work. Is it something about Ubuntu Server, or a misconfiguration on my part where I haven't followed the standards, or even hardware requirements? (By the way, I'm enthusiastic about installing and trying things on my home server, so I'm not very expert.).
Thanks.
A few days ago, I completed the NextJs course, and I successfully deployed it on Vercel, which has me really excited. So, I decided to set up the same app on my personal server (it's a modest and old PC) running Ubuntu Server 24, using a Cloudflare tunnel to make it accessible through a Cloudflare domain (since I don't want to pay for a public IP), and Nginx as a proxy server redirecting to the application on localhost:3000.
However, I'm encountering the error: Illegal Instruction (core dumped).
After a lot of trial and error, I discovered that the issue is related to the Image component (next/image). When it tries to optimize the image, it throws an error, causing the application to crash. I'm not entirely sure why this happens, but if I set the directive unoptimized: true in next.config, it works perfectly. So, I believe the problem lies with the image optimizer.
I've tried numerous things (inspired by Microsoft Copilot), such as setting the user to www-data (or was it data-www, I can't recall exactly), checking file permissions (some are 755 and others are 644).
Configurations in Nginx to alias _next/image to / .next/media result in permission denied errors in the Nginx error log. I'd like to know if there's something I haven't considered about the image optimization processes or settings in NextJs.
I should clarify that I could use unoptimized: true, and the <img> tags get a normal path like /hero-desktop.png, which works and not the /_next/image?url=etcetcetc . But I want to know if there's something I haven't considered to make NextJs's image optimization work. Is it something about Ubuntu Server, or a misconfiguration on my part where I haven't followed the standards, or even hardware requirements? (By the way, I'm enthusiastic about installing and trying things on my home server, so I'm not very expert.).
Thanks.
8 Replies
MilkfishOP
The image link do not found.
My Image Component,
My Syslog, at the moment of crash (trying to load that image)
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET / HTTP/1.1" 200 13537 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/css/app/layout.css?v=1738031515079 HTTP/1.1" 200 9104 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/webpack.js?v=1738031515079 HTTP/1.1" 200 10598 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/app-pages-internals.js HTTP/1.1" 200 83241 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/app/page.js HTTP/1.1" 200 143048 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:58 +0000] "GET /_next/static/chunks/main-app.js?v=1738031515079 HTTP/1.1" 200 248039 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:58 +0000] "GET /_next/image?url=%2Fhero-desktop.png&w=1080&q=75 HTTP/1.1" 502 568 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
My NginxLog
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/css/app/layout.css?v=1738031515079 HTTP/1.1" 200 9104 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/webpack.js?v=1738031515079 HTTP/1.1" 200 10598 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/app-pages-internals.js HTTP/1.1" 200 83241 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:57 +0000] "GET /_next/static/chunks/app/page.js HTTP/1.1" 200 143048 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:58 +0000] "GET /_next/static/chunks/main-app.js?v=1738031515079 HTTP/1.1" 200 248039 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
127.0.0.1 - - [28/Jan/2025:02:31:58 +0000] "GET /_next/image?url=%2Fhero-desktop.png&w=1080&q=75 HTTP/1.1" 502 568 "https://devnext.dkitsoft.dev/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
My NginxLog
Can you provide site url?
could you provide us with your nginx config
MilkfishOP
Hello, the URL I'm using is devnext.dkitsoft.dev, which points to localhost:3001.
the command i used is sudo pnpm dev -p 3001
I don't have it running as a service yet, so if you try to access the root (i.e., /), which contains the Image component from next/image, it will give an error and I'll need to restart the development environment.
The other routes like /dashboard use a component I created with Copilot's help, and they provide a regular URL without going through the optimizer, so they don't cause any problems.
and here is my nginx config inside sites-available/
the command i used is sudo pnpm dev -p 3001
I don't have it running as a service yet, so if you try to access the root (i.e., /), which contains the Image component from next/image, it will give an error and I'll need to restart the development environment.
The other routes like /dashboard use a component I created with Copilot's help, and they provide a regular URL without going through the optimizer, so they don't cause any problems.
and here is my nginx config inside sites-available/
MilkfishOP
WHen i try to get an file that not exist, do not crash!.