CentOS7 ngixn 설치하는 방법입니다. yum 외부 저장소를 추가하여 설치해야 됩니다.
1. yum 외부 저장소 추가
/etc/yum.repos.d/에 nginx.repo 파일을 생성합니다.
vi /etc/yum.repos.d/nginx.repo
vi를 통해서 아래 내역 nginx.repo에 저장소 정보를 입력합니다.
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
2. yum install
yum을 통해서 설치가 가능합니다. yum install 명령어를 이용해 설치하면 됩니다.
yum install -y nginx
-y(--assumeyes) 옵션은 모든 물음에 "예"를 선택하는 옵션입니다.
3. 방화벽 설정
사용할 방화벽 포트를 열어줍니다. 아래 순서대로 80포트 TCP 허용, 변경된 설정 다시 읽기, 허용된 포트 확인 순입니다.
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload
firewall-cmd --list-ports
FirewallD is not running로 firewall-cmd 가 실행되지 않는 경우 systemctl start firewalld 를 입력하면 해결됩니다.
systemctl start firewalld
4. nginx conf 설정
/etc/nginx/conf.d/default.conf에서 기본 conf 설정을 확인할 수 있습니다. 포트 변경이나 원하는 설정을 추가 제거하면 됩니다.
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
5. nginx 실행
systemctl start nginx
systemctl enable nginx
6. 확인
nginx 정상 확인 방법은 로컬인 경우 http://localhost:80 으로 접속, 외부 장비일 경우 IP로 접근하면 nginx welcome 페이지를 확인할 수 있습니다.
