Proxy to nginx unix socket

I am trying to connect to nginx socket. but I can’t get the path right for it is generated every time Nginx is started.
If I use “unix:/var/run/nginx.sock” it works but I need to delete /var/run/nginx.sock every time I start nginx or it will not start.

Caddy

mysite.com {
tls off
proxy / unix:/tmp/systemd-private-*-nginx.service-*/tmp/nginx.sock
}

Nginx

server {
listen unix:/tmp/nginx.sock;
server_name mysite.com;
root /home/site/mysite.com/;
}

I fix the problem by editing /usr/lib/systemd/system/nginx.service
and added

ExecStopPost=/bin/rm -f /var/run/nginx.sock

Also added in nginx.conf inside of http { so I get the real remote ipaddress

##Proxy unixsocket	
	set_real_ip_from  unix:;
	real_ip_header    X-Forwarded-For;
	real_ip_recursive on;

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.