CentOS7 LEMP NGINX 가상 호스트 설정
1. 가상 호스트 설정파일 생성
# vim /etc/nginx/conf.d/mydomain.com.conf
아래와 같이 내용을 기입한다.
server {
server_name mydomain.com;
listen 80;
root /srv/www/mydomain.com;
access_log /var/log/nginx/mydomain.com-access.log;
error_log /var/log/nginx/mydomain.com-error.log;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ /.ht {
deny all;
}
location ~ .php {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
server_name mydomain.com;
listen 80;
root /srv/www/mydomain.com;
access_log /var/log/nginx/mydomain.com-access.log;
error_log /var/log/nginx/mydomain.com-error.log;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ /.ht {
deny all;
}
location ~ .php {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
2. 테스트 및 nginx 재시작
# nginx -t
# systemctl restart nginx
3. 가상호스트 폴더
1번에서 입력한 root 에 대한 폴더를 생성한다.
# mkdir -p /srv/www/mydomain.com
테스트를 위한 파일 생성
# echo -e "<?phpntphpinfo();" > /srv/www/mydomain.com/info.php
해당 폴더 권한을 nginx에게 부여
# chown nginx: -R /srv/www/
접속하여 php 정보가 뜨는 지 확인.