Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the An insecure WebSocket problem of using nginx to configure ssl certificate

Shulou Source: shulou.com Published: 2022-06-01 23:13:30 10月24日 Update

This article mainly explains "how to solve the An insecure WebSocket problem of using nginx to configure ssl certificate", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "how to solve the An insecure WebSocket problem of using nginx to configure ssl certificate"!

Question:

Use nginx to configure the ssl certificate. When deploying the project, it is found that the ws protocol has failed and must be changed to the wss protocol. Websocket uses ws or wss, which is similar to HTTP or HTTPS, where wss represents Websocket on top of TLS, which is equivalent to HTTPS. By default, Websocket's ws protocol uses port 80. When running on TLS, the wss protocol uses port 443 by default.

Solution method

Refer to the official document: http://nginx.org/en/docs/http/websocket.html

Add the following configuration to nginx:

Location / websocket {proxy_pass http://myblog.lwenhao.com:8080/myblog/websocket; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";}

Need the agent to forward to your real websocket address. I applied for a free ssl certificate for the domain name on Ali. The front end can only request it through the domain name applying for the certificate, not through the first-and second-level domain names.

Note:

By default, if the proxy server does not transfer any data within 60 seconds, the connection is closed. Use the proxy_read_timeout directive to increase this timeout. Alternatively, the proxy server can be configured to send WebSocket ping frames periodically to reset the timeout and check if the connection still exists.

Thank you for your reading, the above is the content of "how to solve the An insecure WebSocket problem of using nginx to configure ssl certificate". After the study of this article, I believe you have a deeper understanding of how to solve the An insecure WebSocket problem of using nginx to configure ssl certificate, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Certificate configuration problem domain name situation agent learning content server port service no secondary domain name front end address official that is ideas instructions data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft MySQL Shulou Tech Info MariaDB