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

Proxy to unix: socket #406

Closed
eiszfuchs opened this issue Dec 8, 2015 · 11 comments
Closed

Proxy to unix: socket #406

eiszfuchs opened this issue Dec 8, 2015 · 11 comments
Labels
feature ⚙️ New feature or request

Comments

@eiszfuchs
Copy link

I'm currently writing a blog post as I try to replace nginx with Caddy step by step. My current setup is that I have a bunch of Python applications that I bind to unix: sockets* using gunicorn.
From what I understand, gunicorn isn't exactly FastCGI, so I had to use Caddy's proxy directive.

http://foobar.local {
    tls off
    proxy / unix:/var/www/flask/app.socket
}

This doesn't work as I would expect. I believe because it hasn't been implemented yet.
The socket file is owned by the same user Caddy is running under. Yet the only response I get is 502 Bad Gateway.

Am I missing something or is this hereby considered a feature request?


* I'm using sockets instead of ports because I hate having a spreadsheet with all the ports I use. Sockets are easier to organize.

@mholt
Copy link
Member

mholt commented Dec 8, 2015

Correct, unix sockets are only implemented for the fastcgi directive. Anyone is welcome to implement this for the proxy directive (I can't get around to it right now.)

@mholt mholt added help wanted 🆘 Extra attention is needed feature ⚙️ New feature or request labels Dec 8, 2015
@eiszfuchs
Copy link
Author

Yay! Time to learn Go then! 👍

@mholt
Copy link
Member

mholt commented Dec 8, 2015

@eiszfuchs
Copy link
Author

I'll give it a try. That doesn't look too complicated.

@eiszfuchs
Copy link
Author

Status report

I've made some changes that seem to work.
You can review them here: https://github.com/mholt/caddy/compare/master...eiszfuchs:feature/proxy-socket?expand=1

Using this Caddyfile and running both added JavaScript files gives both responses, socket response and port response.

:2015

log access.log
errors error.log

proxy / localhost:59000 unix:/Users/eiszfuchs/proxy_test

I'm not sure if what I did is exactly what I should be doing, but strangely, it works, so I thought I might share my solution with you so we could talk about the changes I spent my whole day now on to work on the rough edges before I start working on _test.go files.
There's something that bugs me, I had to change parameter types of NewSingleHostReverseProxy because I needed to pass through the proper "host" name when creating a new net.Dial.

As I said, I'm fairly new to Go, though not to programming, and just for the record, I don't think I will use Go very often in the future. Go is so weird. 😊

@abiosoft
Copy link

Looks like we are not far off 👏

If you are gonna create a PR, you will need to remove the gitignore and js files from the commit and a rebase to single commit will be preferred.

Thanks 😊

@eiszfuchs
Copy link
Author

Sure, I'll cleanup before submitting a PR! 👍
I'm not exactly comfortable with that at the moment, especially because my changes are calling url.Parse twice. I'll try to optimize that a bit.

The JavaScript files were meant for tests, the fastcgi middleware does include a PHP file, too.

@eiszfuchs
Copy link
Author

Status report

I was able to refine my changes, clean everything up, remove the garbage and squash everything together: master...eiszfuchs:feature/proxy-socket
Turns out I could just use .String() to get what I needed, no need to change signatures here.

It's still lacking tests, because I've got no clue how to start writing these. :(

@mholt
Copy link
Member

mholt commented Dec 17, 2015

Nice, we can prove they work with some tests. You can do that with net.Listen and specify "unix" as the socket type.

Will probably need to take care that such tests do not fail to compile or run on Windows, as well.

Looking good so far!

@punkeel
Copy link

punkeel commented Dec 25, 2015

👍 <3

@eiszfuchs
Copy link
Author

Then let's move the discussion to a proper Pull request, shall we?

@eiszfuchs eiszfuchs mentioned this issue Dec 28, 2015
3 tasks
@mholt mholt closed this as completed Feb 20, 2016
@mholt mholt removed the help wanted 🆘 Extra attention is needed label Feb 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants