Score:0

Setting up nginx reverse proxy - 500 Internal Server Error

mp flag

I'm trying to set up a reverse proxy server using nginx 1.20.1 on Fedora Server 35, but everything I've tried so far results in an error:

[root@proxy nginx]# curl -I -H "Host: www.example.com" http://10.0.19.1/
HTTP/1.1 500 Internal Server Error
Server: nginx/1.20.1
Date: Wed, 10 Nov 2021 19:54:39 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/8.0.12

10.0.19.1 is the address of the nginx server, and 10.0.20.1 is an Apache server which I'm trying to proxy. If I run the same curl command as above, but using 10.0.20.1 for the URL, it works fine, so I think it's safe to rule out connectivity issues between the two servers, and any problem with the Apache host. The nginx error log is empty.

nginx -t Finds no problems with the config files (reproduced below). I also set SELinux to permissive for now to eliminate that as a cause.

I did create a simple (non-proxy) server configuration to test, and that worked OK, so being new to nginx, I get the feeling this is a probably a very trivial problem with my proxy.conf file.

nginx.conf:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;
}

conf.d/proxy.conf:

server {
    listen 80;
    server_name www.example.com;
    location / {
        proxy_pass http://10.0.20.1;
    }
}
Richard Smith avatar
jp flag
Which server is running PHP? The 500 error is coming from PHP as you can see in the response from `curl`.
us flag
Have a look at the proxied web server's `error.log`.
user3623992 avatar
mp flag
The proxied server isn’t receiving requests at all - error log and access log are both empty.
user3623992 avatar
mp flag
I’m assuming (I know, bad) that the PHP header there is simply because I installed nginx from the Fedora repo, and PHP is installed as a dependency. I am speaking as someone with zero prior experience of nginx though.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.