SasukeFreestyle / XTLS-Iran-TLS

How to make a V2ray (XTLS) Server for bypassing internet censorship in Iran.
GNU Affero General Public License v3.0
74 stars 17 forks source link

bind() to unix:/dev/shm fails on OpenVZ VPS #6

Closed pouriap closed 1 year ago

pouriap commented 1 year ago

Hello and thanks for your comprehensive guide. I am having a problem starting nginx with your provided config file in my OpenVZ VPS. I get the following error when I run systemctl restart nginx:

Mar 14 19:40:14 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:14 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:16 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] still could not bind()
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: nginx.service: Control process exited, code=exited status=1
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: Failed to start A high performance web server and a reverse proxy server.

I'm not sure what this unix:/dev/shm listen address is but I Googled it and it seems it's some kind of memory sharing technique and I suspect maybe it's because I am using OpenVZ that I get this error because OpenVZ itself uses shared memory and is different from a real machine or KVM machines.

SasukeFreestyle commented 1 year ago

Hello! You're welcome!

Yep some VPS'es have this problem.

You can however put the socket in any location you want, that has read/write access.

In both nginx and xray config (fallback destination). Change the path to whatever you prefer that is somewhat secure.

example in nginx

listen unix:/var/run/nginx/h1.sock proxy_protocol;
listen unix:/var/run/nginx/h2c.sock proxy_protocol;

or

listen unix:/tmp/nginx/h1.sock proxy_protocol;
listen unix:/tmp/nginx/h2c.sock proxy_protocol;

e.t.c

in xray config you need then to change to that fallback path Example

"dest":"/var/run/nginx/h1.sock",

if it does not work try another location.

pouriap commented 1 year ago

Thanks that worked.