inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[리뉴얼] React로 NodeBird SNS 만들기

도메인 연결하기

[공유목적] nginx 설정 후 쿠키가 전달되지 않을 경우

해결된 질문

2406

류지혜

작성한 질문수 10

1

 

작성한 이유(저는 이 문제로 골머리를 앓았어서..)

 

backsession 설정

if (process.env.NODE_ENV === "production") {
  app.use(morgan("combined"));
  app.use(hpp());
  app.use(helmet());
  app.set("trust proxy", 1); //배포 시 추가
  app.use(
    cors({
      origin: "https://engword.shop", //local "http://localhost:3000"
      credentials: true,
    })
  );
} else {
  app.use(morgan("dev"));
  app.use(
    cors({
      origin: true,
      credentials: true,
    })
  );
}

passportConfig();

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser(process.env.COOKIE_SECRET));

app.use(
  session({
    saveUninitialized: false,
    resave: false,
    secret: process.env.COOKIE_SECRET,
    proxy: true, //배포 시 추가
    cookie: {
      httpOnly: true,
      secure: process.env.NODE_ENV === "production" ? true : false, //https 적용 시 true
      sameSite: process.env.NODE_ENV === "production" ? "none" : false,
     domain: process.env.NODE_ENV === "production" && ".engword.shop",
    },
  })
);

 

nginx 설정

back 에서 설정한 nginx입니다

sudo vim /etc/nginx/nginx.conf

server {
	server_name api.engword.shop;
    location / {
    	proxy_set_header HOST $host;
        //추가
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
       	proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.0:3000 //http로 설정할 것
        proxy_redirect off;
    }
    //아래는 certbot 내용
}

위와 같이 설정을 바꾼 후 nginx를 다시 실행합니다

sudo systemctl restart nginx

 

pm2로 진행 시 pm2를 껏다 키거나, pm2 재시작을 하시면 됩니다.

pm2 껏다 키는 경우

sudo npx pm2 kill

npm start (혹은 sudo npm start)

pm2 재시작

sudo npx pm2 reload all

redux node.js react express nodejs next.js Next.js

답변 0

넥스트 버젼 질문

0

78

2

로그인시 401 Unauthorized 오류가 뜹니다

0

89

1

무한 스크롤 중 스크롤 튐 현상

0

175

1

특정 페이지 접근을 막고 싶을 때

0

103

2

createGlobalStyle의 위치와 영향범위

0

96

2

인라인 스타일 리렌더링 관련

0

91

2

vsc 에서 npm init 설치시 오류

0

146

2

nextjs 15버전 사용 가능할까요?

0

158

1

화면 새로고침 문의

0

121

1

RTK에서 draft, state 차이가 있나요?

0

153

2

Next 14 사용해도 될까요?

0

452

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

349

1

url 오류 질문있습니다

0

211

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

373

1

sudo certbot --nginx 에러

0

1275

2

Minified React error 콘솔에러 (hydrate)

0

470

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

247

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

327

1

npm run build 에러

0

518

1

front 서버 npm run build 중에 발생한 에러들

0

382

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

338

2

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

0

288

1

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

239

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

201

1