gmaclinuxer
gmaclinuxer

Reputation: 11

Can Hendrix and Nginx work together?

I need push message from backend to frontend in Django, finally I found this Twisted + Django server but in product env we use nginx to proxy request to Django, I'm confused can hendrix and nginx work together?

If yes, then what how to write nginx.conf?

Upvotes: 1

Views: 116

Answers (2)

gmaclinuxer
gmaclinuxer

Reputation: 11

today i try to change my original nginx config to reverse proxy hendrix, here is some snippets:

   upstream django {
        server localhost:8000;
    }
    server {
    listen 80;
    server_name localhost;

    location /static/ {
            #root /var/www;
            alias /var/www/static;
    }

    location / {
            proxy_pass http://django;
            proxy_pass_header Server;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }
    }

then i restart nginx and start hendrix: hx start --log ./test.log

it worked finally, but i found some warning message: *

WebSocket connection to '...' failed: Error during WebSocket handshake: 'Connection' header value is not 'Upgrade': keep-alive socket.io.js:2371

*

after some google message, i found nginx version must higher 1.3.13, so i update nginx to 1.10.1(stable), warning message disappear.

but if want use hendrix in my production env, multi hendrix-worker needed, so i try: hx start -w 2, failed output:

root@proxy:/vagrant/hendrix_taste/hendrix/examples/django_hx_chatserver/example_app# hx start -w 2                                                                                                                                              
Adding media resource for URL 'static' at path '/vagrant/hendrix_taste/hendrix/examples/django_hx_chatserver/example_app/servedstatics'                                                                                                         
...
Adding media resource for URL 'static/admin' at path '/usr/local/lib/python2.7/dist-
'/vagrant/hendrix_taste/hendrix/examples/django_hx_chatserver/example_app/chat/static/chat/js'                                                                                           
Ready and Listening on port 8000...                                                                                                                                                                                                             
{0: 0, 1: 1, 2: 2, 4: 4}                                                                                                                                                                                                                        
{'main_web_tcp': 4}                                                                                                                                                                                                                             
Unhandled Error                                                                                                                                                                                                                                 
Traceback (most recent call last):                                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 180, in run                                                                                                                                                        
    getattr(self, action)(fd)                                                                                                                                                                                                                   
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 226, in start                                                                                                                                                      
    self.launchWorkers(pids)                                                                                                                                                                                                                    
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 265, in launchWorkers                                                                                                                                              
    DeployServerProtocol(args), 'hx', args, childFDs=self.childFDs, env=environ                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 340, in spawnProcess                                                                                                                                        
    processProtocol, uid, gid, childFDs)                                                                                                                                                                                                        
--- <exception caught here> ---                                                                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/process.py", line 756, in __init__                                                                                                                                              
    self.proto.makeConnection(self)                                                                                                                                                                                                             
exceptions.AttributeError: 'DeployServerProtocol' object has no attribute 'makeConnection'                                                                                                                                                      

Unhandled Error                                                                                                                                                                                                                                 
Traceback (most recent call last):                                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 180, in run                                                                                                                                                        
    getattr(self, action)(fd)                                                                                                                                                                                                                   
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 226, in start                                                                                                                                                      
    self.launchWorkers(pids)                                                                                                                                                                                                                    
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 265, in launchWorkers                                                                                                                                              
    DeployServerProtocol(args), 'hx', args, childFDs=self.childFDs, env=environ                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 340, in spawnProcess                                                                                                                                        
    processProtocol, uid, gid, childFDs)                                                                                                                                                                                                        
--- <exception caught here> ---                                                                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/process.py", line 756, in __init__                                                                                                                                              
    self.proto.makeConnection(self)                                                                                                                                                                                                             
exceptions.AttributeError: 'DeployServerProtocol' object has no attribute 'makeConnection'                                                                                                                                                      

Adding media resource for URL 'static' at path '/vagrant/hendrix_taste/hendrix/examples/django_hx_chatserver/example_app/servedstatics'                                                                                                         
...                                                                                   
Ready and Listening on port 8000...                                                                                                                                                                                                             
Unhandled error in Deferred:                                                                                                                                                                                                                    


Traceback (most recent call last):                                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 317, in addCallback                                                                                                                                             
    callbackKeywords=kw)                                                                                                                                                                                                                        
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 306, in addCallbacks                                                                                                                                            
    self._runCallbacks()                                                                                                                                                                                                                        
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 588, in _runCallbacks                                                                                                                                           
    current.result = callback(current.result, *args, **kw)                                                                                                                                                                                      
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1313, in execute                                                                                                                                                
    d = maybeDeferred(f, *args, **kwargs)                                                                                                                                                                                                       
--- <exception caught here> ---                                                                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 150, in maybeDeferred                                                                                                                                           
    result = f(*args, **kw)                                                                                                                                                                                                                     
exceptions.TypeError: _addSubprocess() takes exactly 4 arguments (5 given)                                                                                                                                                                      
Temporarily disabling observer <twisted.logger._filter.FilteringLogObserver object at 0x20bac50> due to exception: [Failure instance: Traceback: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute '_formatter_parser'     
/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py:283:addSubprocess                                                                                                                                                                 
/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py:707:__del__                                                                                                                                                                    
/usr/local/lib/python2.7/dist-packages/twisted/logger/_logger.py:178:failure                                                                                                                                                                    
/usr/local/lib/python2.7/dist-packages/twisted/logger/_logger.py:132:emit                                                                                                                                                                       
--- <exception caught here> ---                                                                                                                                                                                                                 
/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py:131:__call__                                                                                                                                                                 
/usr/local/lib/python2.7/dist-packages/twisted/logger/_filter.py:131:__call__                                                                                                                                                                   
/usr/local/lib/python2.7/dist-packages/twisted/logger/_file.py:50:__call__                                                                                                                                                                      
/usr/local/lib/python2.7/dist-packages/twisted/logger/_json.py:245:<lambda>                                                                                                                                                                     
/usr/local/lib/python2.7/dist-packages/twisted/logger/_json.py:196:eventAsJSON                                                                                                                                                                  
/usr/local/lib/python2.7/dist-packages/twisted/logger/_flatten.py:87:flattenEvent                                                                                                                                                               
/usr/lib/python2.7/string.py:621:parse                                                                                                                                                                                                          
]                                                                                                                                                                                                                                               

Traceback (most recent call last):                                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/hendrix/deploy/base.py", line 283, in addSubprocess                                                                                                                                              
    self._lock.run(self._addSubprocess, self, fds, name, factory)                                                                                                                                                                               
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 707, in __del__                                                                                                                                                 
    debugInfo=debugInfo)                                                                                                                                                                                                                        
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_logger.py", line 178, in failure                                                                                                                                                 
    self.emit(level, format, log_failure=failure, **kwargs)                                                                                                                                                                                     
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_logger.py", line 132, in emit                                                                                                                                                    
    self.observer(event)                                                                                                                                                                                                                        
--- <exception caught here> ---                                                                                                                                                                                                                 
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py", line 131, in __call__                                                                                                                                              
    observer(event)                                                                                                                                                                                                                             
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_filter.py", line 131, in __call__                                                                                                                                                
    self._observer(event)                                                                                                                                                                                                                       
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_file.py", line 50, in __call__                                                                                                                                                   
    text = self.formatEvent(event)                                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_json.py", line 245, in <lambda>                                                                                                                                                  
    lambda event: u"{0}{1}\n".format(recordSeparator, eventAsJSON(event))                                                                                                                                                                       
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_json.py", line 196, in eventAsJSON                                                                                                                                               
    flattenEvent(event)                                                                                                                                                                                                                         
  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_flatten.py", line 87, in flattenEvent                                                                                                                                            
    aFormatter.parse(event["log_format"])                                                                                                                                                                                                       
  File "/usr/lib/python2.7/string.py", line 621, in parse                                                                                                                                                                                       
    return format_string._formatter_parser()                                                                                                                                                                                                    
exceptions.At

my python packages: pip freeze

Warning: cannot find svn location for distribute==0.6.24dev-r0
Automat==0.3.0
Django==1.8.11
GnuPGInterface==0.3.2
Jinja2==2.9.4
MarkupSafe==0.23
PyYAML==3.12
Twisted==16.0.0
apt-xapian-index==0.44
argh==0.26.2
argparse==1.2.1
attrs==16.3.0
characteristic==14.3.0
chardet==2.0.1
command-not-found==0.2.44
configobj==4.7.2
constantly==15.1.0
decorator==3.3.2
## FIXME: could not find svn URL in dependency_links for this package:
distribute==0.6.24dev-r0
hendrix==2.0.2
incremental==16.10.1
ipython==0.12.1
language-selector==0.1
pathtools==0.1.2
pexpect==2.3
pyOpenSSL==16.2.0
pyasn1==0.1.9
pyasn1-modules==0.0.8
pychalk==0.0.5
python-apt==0.8.3ubuntu7.1
python-debian==0.1.21ubuntu1
service-identity==16.0.0
simplegeneric==0.7
six==1.10.0
txsockjs==1.2.2
ufw==0.31.1-1
virtualenv==15.1.0
watchdog==0.8.3
wsgiref==0.1.2
zope.interface==4.0.5

Upvotes: 0

jMyles
jMyles

Reputation: 12172

Yep, you can use nginx to proxy pass to hendrix the same way as you do with any other WSGI/ASGI container.

This Question has sample config for doing this.

Upvotes: 0

Related Questions