티스토리 뷰

IT/Linux

[CentOS7] nginx.conf & default.conf

주인장 진빼이

직접 저장소를 만들어서 nginx 패키지를 다운 받는 것과 epel-release 저장소에서 제공하는 패키지는 서로 다르다.
이번에 리눅스 머신을 재구축할 때 epel-release에서 제공해주는 nginx 패키지를 다운받았다.

404 not found 처리는 404/index.php로 만들어서 메인 페이지로 redirect 시켜주었다.
루트 경로 기본값인 usr/share/nginx/html을 계속 변경시도했지만 실패했다.
└ ln -s 명령어를 사용하여 링크 만들어서 원하는 경로와 usr/share/nginx/html을 연결시켜주었다.

패키지 버전에서는 /etc/nginx/nginx.conf에 server { } 정보가 포함되어 있었다.
이를 모두 주석처리 하고 /etc/nginx/conf.d 폴더를 생성 후 default.conf에 서버 블록 정보를 담아주었다.
conf.d와 동일한 경로에 default.d 폴더를 만들어서 conf를 넣어보고 접속 테스트는 실패였다.

etc/nginx/conf.d/default.conf (*.conf)

server {
        listen      80;

        root         /usr/share/nginx/html;
        index index.html index.htm index.php;

        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf; 주석 해제되어 있으나, 주석해도 문제 없이 잘 작동한다.

        location / {
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /\.ht {
             deny  all;
        }
        error_page 404 /404;
        location = /404 { # php 404 redirect
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
}

/etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    server_tokens     off;
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

#    server {
#        listen       80 default_server;
#        listen       [::]:80 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#        root         /html_www;
#        index index.html index.htm index.php;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#       autoindex on;
#    autoindex_exact_size off;
#        }
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }

}
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함