Detailed explanation of spring boot websocket integration and nginx configuration

preface

This article mainly introduces the spring boot websocket integration and nginx configuration for your reference. Let's take a look at the detailed introduction.

1: Spring boot websocket integration

Create a maven project and add the following dependencies

The code is as follows:

application. The properties are as follows:

src/main/resources/webapp/html/index. The HTML content is as follows:

Finally, start the main method to access http://127.0.0.1:9080/index.html You can see the output

2: Nginx configuration

Nginx supports WebSockets by establishing a tunnel between the client and the back-end server.

In order for nginx to send the upgrade request from the client to the back-end server, the header information of upgrade and connection must be explicitly set. As follows:

Once we complete the above settings, nginx can handle websocket connections.

Note: you must have a proxy_ set_ header Host $host:$server_ port; This configuration

Otherwise, it will report: websocket connection to 'WS: / / 192.168 1.104:9080 / Web / count 'failed: error during websocket Handshake: unexpected response code: 403

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>