# Local's router doesn't proxy websockets

**URL:** <https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005>\
**Category:** Support\
**Tags:** nginx, router-mode\
**Created:** [November 19, 2020, 4:32am UTC](https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005 "2020-11-19T04:32:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonaskuske](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/jonaskuske/32/11849_2.png) [@jonaskuske](https://community.localwp.com/u/jonaskuske)\
**Post date:** [November 19, 2020, 4:32am UTC](https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005/1 "2020-11-19T04:32:31Z")

</div>

### Issue Summary

The nginx config that Local uses for its router does not forward the two headers necessary for web socket connections: ‘Connection’ and ‘Upgrade’. Specifically, `router-config/location-block.conf` is missing these lines:

```
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;

```

If I add them manually, in my case in `%LocalAppData%\Programs\Local\resources\extraResources\router-config\location-block.conf`, everything works fine.

#### Troubleshooting Questions

- Does this happen for all sites in Local, or just one in particular?

Should happen to all sites that need to handle websocket connections. (only tried with Apache sites so far though)

- Are you able to create a new, plain WordPress site in Local and access it in a Browser?

Yes

#### Replication

As stated above, this should be replicable by any site accepting web socket connections.

However, my usecase is proxying the websocket connection of my Vue CLI frontend to the webpack-dev-server for hot module reload while still being able to use `https` (and `wss`, respectively):

1. Create a new site in Local and trust the certificate.

2. Chose Apache as server and add this to `config/apache/site.conf.hbs` in your project folder:

```
ProxyPass /sockjs-node/ http://localhost:8080/sockjs-node/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /sockjs-node/(.*) ws://localhost:8080/sockjs-node/$1 [P,L]

```

Also add this to `config/apache/modules.conf.hbs` to load the proxy modules:

```
LoadModule proxy_http_module "{{ modules }}/mod_proxy_http.so"
LoadModule proxy_wstunnel_module "{{ modules }}/mod_proxy_wstunnel.so"

```

1. Create a Vue CLI project: `npx -p @vue/cli vue create -dbn --skipGetStarted my-theme`

2. Configure the Vue project to work with Local/WordPress by adding these files:

**vue.config.js** :

```
module.exports = {
  // or create a symlink .../wp-content/themes/my-theme → ./dist
  outputDir: '/path/to/local-site/app/public/wp-content/themes/my-theme',
  publicPath: '/wp-content/themes/my-theme/',
  indexPath: 'index.php',
  devServer: { writeToDisk: true, public: 'your-local-site-host.local' }
}

```

**public/style.css** :

```
/*
Theme Name: WebSocket Repro
Version: 1.0.0
*/

```

1. Start the dev server with `npm run serve`, restart your Local site, go to your WordPress admin page and activate `WebSocket Repro`, then visit the site

2. Check the console or network tab in DevTools. Instead of a single WebSocket connection there are a lot of failed requests as `sockjs` goes through the various possible fallback options.

#### System Details

- Which version of Local is being used?

5.9.2+5056

- What Operating System (OS) and OS version is being used?

Windows 10 Pro version 20H2 (Build 19042.630)

---

<div class="post-metadata">

**Author:** ![jonaskuske](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/jonaskuske/32/11849_2.png) [@jonaskuske](https://community.localwp.com/u/jonaskuske)\
**Post date:** [December 22, 2020, 10:55am UTC](https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005/2 "2020-12-22T10:55:54Z")

</div>

Forgot that the line `proxy_http_version 1.1;` is missing too in `router-config/location-block.conf` 👆

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/system/32/1_2.png) [@system](https://community.localwp.com/u/system)\
**Post date:** [March 22, 2021, 10:55am UTC](https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005/3 "2021-03-22T10:55:56Z")

</div>

Closed on March 22, 2021, 10:55am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![ben.turner](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/ben.turner/32/5366_2.png) [@ben.turner](https://community.localwp.com/u/ben.turner)\
**Post date:** [August 10, 2021, 5:29pm UTC](https://community.localwp.com/t/locals-router-doesnt-proxy-websockets/23005/4 "2021-08-10T17:29:00Z")

</div>

Opened on August 10, 2021, 5:29pm UTC


