aws EC2 ํ์ฉ ์ค nginx ์ค์ ๋ฐ ๊ถํ ์ด์
EC2๋ก ํ๋ก ํธ React๋ฅผ ๋ฐฐํฌํ๊ธฐ ์ํด Nginx๋ฅผ ์ฌ์ฉํ๋ฉด์ ๊ถํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค!!
๊ถํ ์๋ฌ
"""
sudo tail -f /var/log/nginx/error.log 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [crit] 7582#7582: *2 stat() "/home/ubuntu/teammap-frontend-pipeline/index.html" failed (13: Permission denied), client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/" 2024/05/04 05:55:08 [error] 7582#7582: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 59.11.133.163, server: 3.12.107.101, request: "GET /favicon.ico HTTP/1.1", host: "3.12.107.101", referrer: "http://3.12.107.101/"
"""
์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด
sudo chmod 755 /home/ubuntu
๋ช
๋ น์ด๋ฅผ ์์ฑํด์คฌ๋ค.
์ดํ,
sudo -u www-data cat /home/ubuntu/teammap-frontend-pipeline/index.html
๋ฅผ ์์ฑํด์ค์ผ๋ก์จ www-data๊ฐ ์ ๊ทผ์ด ๊ฐ๋ฅํ๊ฒ ํด์คฌ๋ค.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/assets/icon-DfLVdc98.png" class="bg-indigo-800" />
<link href="https://fonts.googleapis.com/css2?family=Jua&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Nanum+Myeongjo&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Song+Myung&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Gugi&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Hahmlet&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Gowun+Batang&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Orbit&display=swap" rel="stylesheet">
<!-- ์์ -->
<!-- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.min.js"></script> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" async defer
src="//dapi.kakao.com/v2/maps/sdk.js?appkey=0ed864a6358904fb3dd1f67c07afc0ae&autoload=false&libraries=services"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.126.1/build/three.min.js"></script>
<title>์ฐ์ฃผํด</title>
<script type="module" crossorigin src="/assets/index-BrrWTV2P.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B2AM09Tq.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
์ด๋ ๊ฒ ๋ฌด์ฌํ ์ ๊ทผ์ด ๊ฐ๋ฅํ ๊ฒ์ ๋ณผ ์ ์๊ณ Nginx ๊ฐ ์คํ์ด ๋๋ฉด์ ๋ฌด์ฌํ ๋ฐฐํฌ๊ฐ ๊ฐ๋ฅํ๋ค.
๋ฌธ์ ์ ์์ธ
๋ฌธ์ ์ ์์ธ๊ณผ ํด๊ฒฐ ๊ณผ์ ์ ์ข
ํฉ์ ์ผ๋ก ์ดํดํ๊ธฐ ์ํด์๋, ํ์ผ ์์คํ
๊ถํ, ์ด์ ์ฒด์ ์ ๋ณด์ ์ ์ฑ
, ๊ทธ๋ฆฌ๊ณ ์น ์๋ฒ ์ค์ ์ด ์ด๋ป๊ฒ ์ํธ ์์ฉํ๋์ง๋ฅผ ํ์
ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค. ์ฌ๊ธฐ์ ๋ฐ์ํ ๋ฌธ์ ๋ ์ฃผ๋ก ๋ฆฌ๋
์ค ํ์ผ ์์คํ
์ ๊ถํ ์ค์ ๊ณผ ๊ด๋ จ์ด ์์์ผ๋ฉฐ, ํนํ ์น ์๋ฒ์ธ Nginx๊ฐ ์คํ๋๋ ์ฌ์ฉ์(www-data)์ ํ์ผ ์ ๊ทผ ๊ถํ์ด ์ค์ฌ์ด์์ต๋๋ค.
- ๊ถํ ์ค์ : /home/ubuntu ๋๋ ํ ๋ฆฌ์ ๋ํ ์ ๊ทผ ๊ถํ์ด ubuntu ์ฌ์ฉ์์๊ฒ๋ง ์ ํ์ ์ผ๋ก ๋ถ์ฌ๋์ด ์์์ต๋๋ค (drwxr-x---). ์ด ์ค์ ์ www-data ์ฌ์ฉ์๊ฐ ์ด ๋๋ ํ ๋ฆฌ ์๋์ ์์นํ index.html ํ์ผ์ ํฌํจํ ๋ชจ๋ ํ์ผ์ ์ ๊ทผํ๋ ๊ฒ์ ๋ฐฉํดํ์ต๋๋ค.
- ์น ์๋ฒ ์ฌ์ฉ์: Nginx๋ ์ผ๋ฐ์ ์ผ๋ก www-data ์ฌ์ฉ์ ๊ณ์ ์ผ๋ก ์คํ๋ฉ๋๋ค. ์น ์๋ฒ๊ฐ ์น ์ฝํ ์ธ ๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด์๋ ํด๋น ํ์ผ๊ณผ ๋๋ ํ ๋ฆฌ์ ์ ๊ทผ ๊ถํ์ด ์์ด์ผ ํฉ๋๋ค.
- SELinux ๋ฐ AppArmor: ๋ฆฌ๋ ์ค ๋ฐฐํฌํ์ ๋ฐ๋ผ SELinux๋ AppArmor์ ๊ฐ์ ์ถ๊ฐ ๋ณด์ ์ ์ฑ ์ด ํ์ผ ์ ๊ทผ์ ์ํฅ์ ์ค ์ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ, SELinux๋ ๋นํ์ฑํ๋์ด ์์์ผ๋, ์ด๋ฌํ ๋ณด์ ๋ชจ๋์ด ํ์ฑํ๋์ด ์๋ค๋ฉด ๋ฌธ์ ์ ์์ธ์ด ๋ ์ ์์ต๋๋ค.
ํด๊ฒฐ ๊ณผ์
- ๊ถํ ๋ณ๊ฒฝ: /home/ubuntu ๋๋ ํ ๋ฆฌ์ ๊ถํ์ 755 (drwxr-xr-x)์ผ๋ก ๋ณ๊ฒฝํ์ฌ, ๋ชจ๋ ์ฌ์ฉ์๊ฐ ๋๋ ํ ๋ฆฌ๋ฅผ ์ฝ๊ณ ์คํํ ์ ์๊ฒ ํ์ต๋๋ค. ์ด๋ฅผ ํตํด www-data ์ฌ์ฉ์๋ /home/ubuntu/teammap-frontend-pipeline/index.html ํ์ผ์ ์ ๊ทผํ ์ ์๊ฒ ๋์์ต๋๋ค.
- ํ์ผ ์ ๊ทผ ํ ์คํธ: ๊ถํ ๋ณ๊ฒฝ ํ www-data ์ฌ์ฉ์๋ก ํ์ผ์ ์ ๊ทผํ๋ ๊ฒ์ ํ ์คํธํ์ฌ ๊ถํ ์ค์ ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ ์ฉ๋์๋์ง ํ์ธํ์ต๋๋ค.
- Nginx ์ฌ์์: ๊ถํ ๋ณ๊ฒฝ์ ์๋ฃํ ํ, Nginx๋ฅผ ์ฌ์์ํ์ฌ ๋ชจ๋ ์ค์ ์ ์๋ก๊ณ ์นจํ๊ณ ์ ์ฉํ์ต๋๋ค.
- ๋ธ๋ผ์ฐ์ ์์์ ํ ์คํธ: ์ต์ข ์ ์ผ๋ก ์น ๋ธ๋ผ์ฐ์ ๋ฅผ ํตํด ์น ์ฌ์ดํธ์ ์ ์ํ์ฌ ๋ณ๊ฒฝ์ฌํญ์ด ์ ๋๋ก ๋ฐ์๋์๋์ง ํ์ธํ์ต๋๋ค.
์ค์ ํฌ์ธํธ
- ๊ถํ: ๋ฆฌ๋ ์ค ์์คํ ์์ ํ์ผ๊ณผ ๋๋ ํ ๋ฆฌ์ ๋ํ ๊ถํ์ ์ฌ์ฉ์์ ํ์ผ ์ ๊ทผ์ฑ์ ๊ฒฐ์ ์ง๋ ์ค์ํ ์์์ ๋๋ค. ์น ์๋ฒ ์ค์ ์, ์น ์ฝํ ์ธ ํ์ผ์ ๋ํ ์ฌ๋ฐ๋ฅธ ๊ถํ ๋ถ์ฌ๋ ํ์์ ์ ๋๋ค.
- ๋ณด์ ์ ์ฑ : SELinux๋ AppArmor ๊ฐ์ ๋ณด์ ์ ์ฑ ์ด ํ์ฑํ๋ ๊ฒฝ์ฐ, ์ด ์ ์ฑ ์ด ์น ์๋ฒ์ ํ์ผ ์ ๊ทผ์ ์ ํํ ์ ์์ผ๋ฏ๋ก, ์ด๋ฅผ ๊ณ ๋ คํด์ผ ํฉ๋๋ค.
- ๋๋ฒ๊น : ๊ถํ ๋ฌธ์ ํด๊ฒฐ ์, ls -l, ls -ld์ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๊ถํ์ ํ์ธํ๊ณ , sudo -u www-data ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ์ค์ ์น ์๋ฒ ์ฌ์ฉ์์ ๊ด์ ์์ ํ์ผ ์ ๊ทผ์ ํ ์คํธํ๋ ๊ฒ์ด ์ ์ฉํฉ๋๋ค.
์ด๋ฌํ ์ง์์ ๋ฆฌ๋ ์ค ๊ธฐ๋ฐ ์์คํ ์์ ํํ ๋ฐ์ํ ์ ์๋ ์ ์ฌํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
AWS ํ๊ฒฝ์์ ๋ณด์ ์ดํด์ ์๋ํ ๊ตฌ์ฑ (0) | 2025.05.12 |
---|---|
์ ์ฒด์ ์ธ AWS ์ํคํ ์ณ๋ฅผ ํ์ ํ๊ณ ๊ธฐ๋ฅ ๋ฐ ๋ณด์ ์ดํด (1) | 2025.05.12 |
Nginx 503 Service Temporarily Unavailavle ๋ฐ์ ํด๊ฒฐ (0) | 2024.05.23 |
AWS์์ https ์ ์ฉํ๊ธฐ (1) | 2024.05.23 |
IaaS์ธ EC2 ์ธ์คํด์ค ์์ฑ๊ณผ ์๋ฒ ์ฐ๊ฒฐ (6) | 2024.02.25 |
๋๊ธ