WEB Server - NGINX 구성파일 및 기본설정 - CentOS 7
WEB Server - NGINX 구성파일 및 기본설정 - CentOS 7
이번 포스팅에서는 Nginx 구성 파일 및 설정에 대해서 알아보겠습니다.
이전 글 :
서버와 클라이언트 그리고 HTTP - https://server-talk.tistory.com/291
NGINX 구성파일 |
NGINX 구성 설정정보
conf/nginx.conf - NGINX 의 기본 구성 설정정보
conf/mime.types 파일 확장자와 연관된 MIME 타입의 목록 구성 설정정보
conf/fastcgi_params - Fast CGI 관련 구성 설정정보
conf/roxy.conf - 프록시 관련 구성설정 정보
sites-available/사이트.conf - NGINX 가상호스트 설정정보
NGINX 기본 구성파일 - nginx.conf |
[root@nginx html]# vi /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root 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 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
NGINX 초기 설치 시 위 설정이 기본 구성 파일 입니다
worker_processes 1 : NGINX를 실행할때 프로세스를 지정하는 부분입니다 CPU 코어 당 숫자를 지정하며 auto를 설정하여 최적화를 하여도 됩니다 기본값은 1입니다
worker_connections 1024 : 1개의 프로세스에서 동시 처리할 수 있는 접속자 수를 지정하는 부분입니다 worker_processes * worker_connections = 총 동시에 처리할 수 있는 접속자를 의미합니다
NGINX 인코딩 설정파일 - mime.type |
include mime.types;
nginx.conf 파일에 인클루드 하여 mime 타입을 지정합니다.
NGINX 가상호스트 설정파일 - 사이트.conf |
include [NGINX 설치경로]/sites-available/*.conf;
server {
listen 192.168.85.177:80;
server_name server-talk.com;
root /home/server_talk/public_html;
#charset koi8-r;
access_log /usr/local/nginx/logs/server-talk.com.access.log;
error_log /usr/local/nginx/logs/server-talk.com.error.log;
#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 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;
#}
}
위 내용과 같이 Nginx에서는 include로 *(Wildcard) 파일명을 지정하는 방식도 지원합니다
sites-available 디렉토리는 NGINX 설치 시 생성되지 않으며, 사용을 원하는 디렉토리 명으로 생성하고 사이트를 생성하면 됩니다.