Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image issue on production : "url" parameter is valid but upstream response is invalid #56935

Closed
1 task done
mcasters opened this issue Oct 17, 2023 · 3 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked

Comments

@mcasters
Copy link

Link to the code that reproduces this issue

https://github.com/mcasters/coucou.git

To Reproduce

  1. Create-next-app
  2. Add an image (jpeg, png, webp) in public folder and create next to the logo a next/image component pointing on the file :

<Image src="/n.jpg" alt="image" width={180} height={230} />

  1. Create a basic custom server (server.js) at root:

`
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');

const port = parseInt(process.env.PORT || '3000', 10)
const hostname = 'localhost'
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()

app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(port)
})
`

  1. Update commands in package.json :

"scripts": { "dev": "NODE_ENV=development node server.js", "build": "next build", "start": "cross-env NODE_ENV=production node dist/server.js", "lint": "next lint" },

  1. Deploy on Cpanel (Setup Node.js App with server.js as Application startup file)

Current vs. Expected behavior

The home page should display the new image next to the logo, but only the logo is displayed.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Tue Aug 9 14:38:15 UTC 2022
Binaries:
  Node: 18.16.1
  npm: 9.5.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.6-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

I open this issue since #53715 is closed and next@13.5.5 didn't solve my problem. I also tried v13.5.6-canary.1

Only svg images are displayed, but jpeg, jpg, png, webp throw TypeError: fetch failed.
Https or http doesn't change anything.

Log from server :
server.log

Log from client :
"url" parameter is valid but upstream response is invalid

Network :
Résumé
URL: http://xxxxxx.fr/_next/image?url=%2Fn.jpg&w=256&q=75
État: 500 Internal Server Error
Source: Réseau
Adresse: 109.234.162.107:80
Initiateur:
xxxxxx.fr:1

Requête
GET /_next/image HTTP/1.1
Accept: image/webp,image/avif,image/jxl,image/heic,image/heic-sequence,video/;q=0.8,image/png,image/svg+xml,image/;q=0.8,/;q=0.5
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Host: xxxxxx.fr
Pragma: no-cache
Referer: http://xxxxxx.fr/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15

Réponse
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Tue, 17 Oct 2023 13:00:13 GMT
Server: o2switch-PowerBoost-v3
Status: 500 Internal Server Error
Transfer-Encoding: Identity
X-Powered-By: Phusion Passenger(R) 6.0.18

Paramètres de chaîne de requête
url: /n.jpg
w: 256
q: 75

Maybe relevant : the image has "txt" type and its name (n.jpeg) is not entered :

Capture d’écran 2023-10-17 à 15 25 17
@mcasters mcasters added the bug Issue was opened via the bug report template. label Oct 17, 2023
@balazsorban44 balazsorban44 added the Image (next/image) Related to Next.js Image Optimization. label Oct 17, 2023
@ian-cameron
Copy link

ian-cameron commented Feb 12, 2024

Same issue, and we are also using Phusion Passenger application server. It looks like ImageOptimzer in the next server is fetching the original image URL from itself, but is not handling the fact that Passenger does reverse port binding

I'm using Next 14.1 with Passenger, and to work around this error I hardcoded my apps root URL from node_modules/next/dist/server/next-server.js:600 from

const invokeRes = await (0, _invokerequest.invokeRequest)(`${protocol}://${this.fetchHostname || "localhost"}:${this.port}${newReq.url || ""}`, {

to

const invokeRes = await (0, _invokerequest.invokeRequest)(`http://myrealdomain.com${this.port}${newReq.url || ""}`, {

Then images worked again.

EDIT:
Noticed this comment, and confirmed the problem went away in the canary version

@styfle
Copy link
Member

styfle commented Feb 13, 2024

Noticed #59123 (comment), and confirmed the problem went away in the canary version

Yep, this is fixed so I'll close this issue now, thanks!

@styfle styfle closed this as completed Feb 13, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked
Projects
None yet
Development

No branches or pull requests

4 participants