yum search nginx(설치할 nginx 찾기)
sudo yum install nginx(sudo 권한으로 nginx 설치)
sudo service nginx status(실행 중인지 아닌지 알 수 있음)
sudo service nginx start(nginx 실행시킨다)
netstat -tnl | grep 80(열린 포트 확인 (80만))
sudo vi /etc/nginx/conf.d/pf.conf(sudo 권한으로 생성한다)
server {
listen 80;
server_name (ipv4_public_dns);
charset UTF-8;
access_log /var/log/nginx/pf/pf.access.log;
error_log /var/log/nginx/pf/pf.error.log;
location /pf {
proxy_redirect off;
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;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8080/pf;
}
location ~ /\.ht {
deny all;
}
}
i(insert 모드)
esc(insert 모드 해제하기)
:wq(저장하고 나가기)
nginx -t(설정파일 검사)
sudo service nginx reload(설정파일 적용 위해 reload)
❗️에러 발생 - 1❗️
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
cd /var/log/nginx
ll
- /var/log/nginx/ 소유자 변경하기
sudo chown nginx:nginx /var/log/nginx/* -R
(chown : 파일 소유권 변경하는 명령어, -R : 하위폴더 모두 다)
sudo su(root 권한으로 실행)
⭐️ root 권한은 위험! 확인만 하기!
chown nginx:nginx -R /var/log/nginx
nginx -t (설정파일 검사)
❗️에러 발생 - 2❗️
nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
nginx: configuration file /etc/nginx/nginx.conf test failed
vi /etc/nginx/nginx.conf
- 크기 변경하기
http {
.....
access_log;
server_names_hash_bucket_size 128;
.....
}
nginx -t (설정파일 검사)
❗️에러 발생 - 3❗️
nginx: [emerg] open() "/var/log/nginx/pf/pf.access.log" failed (2: No such file or directory)
(폴더가 없어서 발생)
cd /var/log/nginx/
ll -al(폴더가 없는 것 확인)
mkdir pf(폴더 만들기)
ll -al(확인)
nginx -t
exit(root 권한 해제하기)
sudo service nginx reload