설치
sudo apt install nginx vim -y
설정파일 오픈
sudo vim /etc/nginx/sites-available/default
수정
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.9/bin/apache-tomcat-10.1.9.tar.gz
tar -xvf apache-tomcat-10.1.9.tar.gz
/usr/local/tomcat/apache-tomcat-10.1.9/bin/startup.sh
netstat -an | grep 8080
sudo systemctl daemon-reload
sudo systemctl --now enable tomcat
sudo systemctl status tomcat --no-pager -l
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:86
nginx: [emerg] unknown directive " " in ~~
nginx.service: Control process exited, code=exited, status=1/FAILURE
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
거의 모든 종류의 nginx 오류를 만나보았답니다. 😇
sudo vim /etc/nginx/sites-available/default
파일에 내용 덮어씌울 때 오타가 있거나,
보통 괄호 또는 따옴표(;)를 생략했을 가능성
EC2 인스턴스 편집 - 8080 포트 추가
Ubuntu 서버에서 root 권한이 아닌데 명령어 치고있는 경우 - 꼭 sudo su
하기
하지만.. 인터넷에 검색해보시는 분들은 보통 다 해보셨을 거에요. ^^;;
✔✔✔ 🔥중요🔥 별표 다섯개!!!! ✔✔✔
오류메시지는 nginx.conf 파일에 문법오류가 있다고 해서 그 설정파일을 눈이 사팔뜨기가 될때까지 쳐다봤지만 문제는 없었다.
cd etc
하면서 폴더와 파일을 하나씩 꼼꼼하게 확인해봤다.
conf.save
라는 헷갈리게 생긴 파일이 있었는데 해당 파일이 어떻게 생겼는지는 모르겠지만 거기엔 중괄호 문제가 있었다.
스왑파일들도 문제가 된다. swap file 삭제하면서 꼭 쓰잘데기없는 파일들도 삭제해주자.
sudo rm 경로/스왑파일명
불필요한 파일들을 삭제해주니 오류 메시지가 뜨지않았다.
sudo lsof -i :80
sudo systemctl stop apache2
sudo systemctl start nginx
sudo service nginx restart
nginx로 고생하는 많은 분들에게 위로를 건넵니다..