SSL을 통해 socketio를 nginx로 설정하려고합니다. 문제는 내가 연결할 클라이언트를 얻을 수 있지만 그 소켓을 통해 올 것으로 예상되는 다른 이벤트를 볼 수 없다는 것입니다.SocketIO with Nginx with SSL
import openSocket from "socket.io-client";
const socket = openSocket(`${SOCKET}`);
function subscribeToTimer(callBack) {
socket.on("timer", timestamp => callBack(null, timestamp));
socket.emit("subscribeToTimer", 1000);
}
export class App extends Component {
constructor(props) {
super(props);
this.store = this.configureStore();
subscribeToTimer((err, action) => this.store.dispatch(action));
}
서버 :
클라이언트 코드는 여기에 있습니다 : (주이 내 프로덕션 서버에서 로컬 작업을 바로하지 않습니다)
: nginx를/etc/nginx/sites-enabled/default
에 의해 관리되는
const port = 8000
const io = require('socket.io')()
io.on("connection", (client) => {
console.log("a user connected")
client.on("subscribeToTimer", (interval) => {
console.log("a user is subscribing to timer with interval: ", interval)
setInterval(() => {
timestamp = new Date()
client.emit('timer', { type: 'SET_TIME', payload: timestamp });
}, interval);
});
})
io.listen(port)
console.log('listening on port ', port)
server {
<snip>
location /socket.io {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
서버를 시작하면 다음과 같이 나타납니다.
listening on port 8000
a user connected
따라서 클라이언트가 서버에 연결하고 있지만 subscribeToTImer
이벤트가 표시되지 않습니다.
여기에 대한 통찰력이 있으십니까?
개발자 콘솔에있는 항목은 무엇입니까? –
@ TarunLalwani 클라이언트 콘솔에는 아무 것도 없었습니다. 나는 실제로 이것을 알아 냈으므로 대답으로 업데이트 할 것이다. – user341493