Setting up a websocket on Apache?

前端 未结 3 676
悲哀的现实
悲哀的现实 2020-12-03 00:53

So I\'m doing some research on websockets, and I have a few questions I can\'t seem to find a definitive answer for:

  • How can I set up a web socket on my Lin

3条回答
  •  暖寄归人
    2020-12-03 01:31

    I struggled to understand the proxy settings for websockets for https therefore let me put clarity here what i realized.

    First you need to enable proxy and proxy_wstunnel apache modules and the apache configuration file will look like this.

    
        
          ServerName www.example.com
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/your_project_public_folder
    
          SSLEngine on
          SSLCertificateFile    /etc/ssl/certs/path_to_your_ssl_certificate
          SSLCertificateKeyFile /etc/ssl/private/path_to_your_ssl_key
    
          
                  Options Indexes FollowSymLinks
                  AllowOverride All
                  Require all granted
                  php_flag display_errors On
          
          ProxyRequests Off 
          ProxyPass /wss/  ws://example.com:port_no
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
        
    
    

    in your frontend application use the url "wss://example.com/wss/" this is very important mostly if you are stuck with websockets you might be making mistake in the front end url. You probably putting url wrongly like below.

    wss://example.com:8080/wss/ -> port no should not be mentioned
    ws://example.com/wss/ -> url should start with wss only.
    wss://example.com/wss -> url should end with / -> most important
    

    also interesting part is the last /wss/ is same as proxypass value if you writing proxypass /ws/ then in the front end you should write /ws/ in the end of url.

提交回复
热议问题