I have a WSGI app that I would like to be listening on multiple addresses. On my machine, 127.0.0.2 is a special interface; I want to listen on that interface as well as on 127.0.0.1 (the regular localhost). Command line syntax proposed:
--bind 127.0.0.1:8080,127.0.0.2:8080
The bind variable could be a string of that form or a list of strings, e.g.
bind = ['127.0.0.1:8080', '127.0.0.2:8080']
It should also be possible to use different ports on the same IP.
Why not use something like this :
--bind 127.0.0.1:8080 --bind 127.0.0.2:8080
optparse will put the values into an array
#!/usr/bin/env python
from optparse import OptionParser
def main():
parser = OptionParser(usage="usage: %prog [options]",
version="%prog 1.0")
parser.add_option('--bind', action="append", dest='outputs', default=[])
(options, args) = parser.parse_args()
print options.outputs
if __name__ == '__main__':
main()
Either way. I just care about having the functionality somehow.
mmm working on this right now. I like having one --bind though or -b though. So it make faster to write -b :8000,:8001 to listen on multiple ports.
I'd say repeating the -b will be less of a WTF than having a special syntax
for the variable itself.
On Mon, Dec 10, 2012 at 11:53 AM, Benoit Chesneau
[email protected]:
mmm working on this right now. I like having one --bind though or -b
though. So it make faster to write -b :8000,:8001 to listen on multiple
ports.—
Reply to this email directly or view it on GitHubhttps://github.com/benoitc/gunicorn/issues/444#issuecomment-11209076.
I've implemented in the PR above this features. for now the syntax is "-b interface1,interface2" . All supported workers can now listen on multiple interfaces.
Need to look on how to support the --append syntax in our Config object ...
new bind syntax implemented in d5ebe040cf6a4b0eb193b3d77625b3722dd40fc3 . Please test!
and legacy syntax supported. I think we are ready for a merge sometimes this week.
Thanks! Shouldn't you update the docs though?
right! I will do it tonight (utc+1 here) with the release on pypi :)
@benoitc -b :
Hey Benoit am trying to bind a port but still giving me default port what could be the issue??..
@tutorialcreation can you show us what you run on the command line? Do you have the PORT
environment variable defined? Any other relevant details? You may also want to open a new issue, as your question seems not quite related to the issue here.
Hello sorry for the late reply, here is my code
#!/bin/bash
NAME="post_retirement" # Name of the application
DJANGODIR=/srv/www/html/post_retirement # Django project directory
SOCKFILE=localhost:8787 # we will communicte using this unix socket
USER=test_account # the user to run as
GROUP=test_account # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=post_retirement.settings # which settings file should Django use
DJANGO_WSGI_MODULE=post_retirement.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /srv/www/html/venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
# RUNDIR=$(dirname $SOCKFILE)
# test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=$SOCKFILE \
--log-level=debug \
--log-file=-
I am binding the port direct but it still gives me the default port 8000
@tutorialcreation I'm not able to reproduce this problem. Please open a new issue where we can debug together further without causing noise for others subscribed to this thread and include your Gunicorn version or a link to your project code. Thanks!
Most helpful comment
@benoitc -b :,: is throwing error as Error: '8082,:8085' is not a valid port number.