nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 320 forks source link

I get 503 error with Images and CSS files #1296

Closed wp-coin closed 3 weeks ago

wp-coin commented 3 weeks ago

are my settings wrong? what is causing my sample php app to block images and linked files?

[app config]

curl -X PUT --data-binary '{
  "listeners": {
      "127.0.0.1:8080": {
          "pass": "applications/php"
      }
  },
  "applications": {
      "php": {
          "type": "php",
          "root": "var/www/mywebsite.org"
      }
  }
  }' --unix-socket /path/to/control.unit.sock http://localhost/config/
Screenshot 2024-05-31 200513

default.conf

upstream my_upstream {
server  127.0.0.1:8080;
}

server {
    listen 80;
    listen [::]:80;
    server_name www.mysite.org;
    root        /var/www/wordpress/;

    # Redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {

    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name mysite.org www.mysite.org;

  include h5bp/tls/ssl_engine.conf;
  include h5bp/tls/certificate_files.conf;
  include h5bp/tls/policy_balanced.conf;

  # Path for static files
  root /var/www/wordpress/;
    index index.html index.php;

# Proxy configuration
    location / {
        proxy_pass http://my_upstream;
        proxy_socket_keepalive on;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Connection "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;

    }

}
lcrilly commented 3 weeks ago

Check the nginx and Unit logs to see where that 503 is coming from.

Your nginx configuration is confusing and ambiguous, with root and location / in the server{} block. How does nginx know which URIs to serve locally, and which ones to proxy to Unit?

I'd recommend to keep nginx as the HTTP/2 front-end and have Unit take care of all the Wordpress parts. Remove the root directive and follow https://unit.nginx.org/howto/wordpress/

wp-coin commented 3 weeks ago

thanks for the info, Unit docs doesn't say much about nginx configuration settings and I don't know much about configuring that.

lcrilly commented 3 weeks ago

Then get it working with Unit and then add NGINX in front for the jobs you need it to do. Unit has no dependency on NGINX and other reverse proxies are available :)

wp-coin commented 3 weeks ago

ok, are the settings on this script wrong? https://gist.github.com/nginx-gists/bdc7da70b124c4f3e472970c7826cccc

the current configs does not seem to be working

wp-coin commented 3 weeks ago

sorry for the bother, I got half of it working, how do I get my unit php server listening on 127.0.0.1:8080 to stream content to nginx via reverse proxy?

currently, nginx is showing the www/html/default.html page

my root is: "root": "var/www/mywebsite.org"

/conf.d/default.conf

server {
    listen 80;
    server_name example.com;

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name example.com;

    # SSL configuration
    ssl_certificate /path/to/certificate.crt;
    ssl_certificate_key /path/to/certificate.key;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
lcrilly commented 3 weeks ago

I already linked to the official Unit documentation for Wordpress. As you have already engaged 3 different members of the Unit team here and in the Gist comments, I will convert this issue to a discussion and encourage you to use that as the preferred channel for assistance.