G
G
gachkydxvbgd2016-06-11 15:22:46
Nginx
gachkydxvbgd, 2016-06-11 15:22:46

How to set up Nginx + nodejs?

How can I do if there is no connect.sid cookie so that nginx would proxy nodejs express (port 8080) and this cookie was created and then the main page of the site was loaded (port 80), and if there is a connect.sid cookie, then we just load the main page (port 80)
A right now it immediately proxies me to nodejs
server {
listen 80;
server_name server.ru www.server.ru;
#Configures the publicly served root directory
#Configures the index file to be served
root /var/www/site;
index index.html index.htm;
#These lines create a bypass for certain pathnames
#www.example.com/test.js is now routed to port 3000
#instead of port 80
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://server.ru:80;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Schoolboy., 2016-06-11
@gachkydxvbgd

Something like this, unfortunately I have never read cookies, I used the answer from here .

server {
listen 8080;
server_name site.dev;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
if($cookie_connect.sid)
{
proxy_pass http://site.dev:80;
}
if($http_cookie !~ "connect.sid")
{
proxy_pass http://site.dev:8080;
}
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question