[Nginx] 페이지 새로고침 시 Page Not Found 오류 해결

2023. 2. 7. 03:48·Trouble Shooting
반응형

이거 왜이래!

Nginx로 배포했던 프로젝트에서 루트 경로가 아닌 다른 하위 경로에서 페이지 새로고침을 하면 404 에러가 발생했다.

 

찾아본 결과 nginx의 config를 파일에서 try_files 부분을 수정해주면 된다는 것을 확인했다.

sudo vi /etc/nginx/sites-available/default

기존의 파일 내용에서 location 부분에서 try_files를 보면 아래와 같이 되어있었다.

기본이 404로 되어있어서 그런 것이었다. 이를 아래와 같이 수정해주면 된다.

try_files $uri /index.html;

 

파일을 저장해준 후, nginx를 다시 켜주면 더이상 새로고침을 해도 404 페이지가 뜨지 않는 것을 확인할 수 있다.

 

sudo systemctl reload nginx

 

 

References

https://stackoverflow.com/questions/43555282/react-js-application-showing-404-not-found-in-nginx-server

 

반응형

'Trouble Shooting' 카테고리의 다른 글

[Next.js] Component selectors can only be used in conjunction with @emotion/babel-plugin 해결  (0) 2023.02.23
[Github Actions] the process '/usr/bin/git' failed with exit code 128 해결  (0) 2023.02.21
[Netlify] 페이지 새로고침 시 Page Not Found 오류 해결  (0) 2023.02.06
inefficient regular expression complexity in nth-check  (0) 2023.01.26
[React] 여러 개 요소 return할 때 key값 지정하기  (0) 2022.12.19
'Trouble Shooting' 카테고리의 다른 글
  • [Next.js] Component selectors can only be used in conjunction with @emotion/babel-plugin 해결
  • [Github Actions] the process '/usr/bin/git' failed with exit code 128 해결
  • [Netlify] 페이지 새로고침 시 Page Not Found 오류 해결
  • inefficient regular expression complexity in nth-check
SH_Roh
SH_Roh
  • SH_Roh
    혼자공부끄적끄적
    SH_Roh
  • 전체
    오늘
    어제
    • 분류 전체보기 (159)
      • FE (39)
        • HTML, CSS (3)
        • Javascript (17)
        • React (11)
        • Next.js (4)
      • Network (1)
      • DevOps (4)
      • Git (1)
      • Trouble Shooting (24)
      • Algorithm (41)
        • Python (2)
        • Data Structure, Algorithm (7)
        • Problem Solving (31)
      • Education (23)
        • Elice AI Track (4)
        • Wanted Pre-Onboarding FE Co.. (19)
      • TIL (25)
      • Etc. (1)
        • 회고 (1)
        • 그냥저냥 (0)
  • 링크

    • Github
  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
SH_Roh
[Nginx] 페이지 새로고침 시 Page Not Found 오류 해결
상단으로

티스토리툴바