작은숲:위키노트/Nginx 가상 호스트 설정: 두 판 사이의 차이

큰숲백과, 나무를 보지 말고 큰 숲을 보라.
잔글 (문자열 찾아 바꾸기 - "분류:소프트웨어 설정" 문자열을 "분류:위키노트/소프트웨어 설정" 문자열로)
잔글 (Utolee90님이 Nginx 가상 호스트 설정 문서를 작은숲:위키노트/Nginx 가상 호스트 설정 문서로 이동했습니다: 제목 변경)
 
(같은 사용자의 중간 판 5개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[위키노트:Nginx|Nginx]]에서는 가상 호스트 설정을 <code>/etc/nginx/conf.d</code> 디렉토리 아래에 호스트별로 저장한다. 이렇게 하는 것이 하나의 파일로 설정할 때보다는 유지보수하는데 편할 수도 있다.
[[작은숲:위키노트/Nginx|Nginx]]에서는 가상 호스트 설정을 <code>/etc/nginx/conf.d</code> 디렉토리 아래에 호스트별로 저장한다. 이렇게 하는 것이 하나의 파일로 설정할 때보다는 유지보수하는데 편할 수도 있다.
아래 내용은 가상 호스트 <tt>example.com</tt>의 설정 파일인 <code>/etc/nginx/conf.d/example.conf</code>의 내용이다.
아래 내용은 가상 호스트 <tt>example.com</tt>의 설정 파일인 <code>/etc/nginx/conf.d/example.conf</code>의 내용이다.
<source lang="nginx">
<syntaxhighlight lang="nginx">
server {
server {
     listen      80;
     listen      80;
25번째 줄: 25번째 줄:
         deny  all;
         deny  all;
     }
     }
}</source>
}</syntaxhighlight>
가상 호스트 설정은 <tt>server</tt> 블럭에 들어간다. 첫 번째 블럭은 <tt>www.example.com</tt>으로 접속한 경우 <tt>example.com</tt>으로 넘겨주는 것이다. 반대의 경우라면 <tt>server_name</tt> 지시자의 값만 바꾸면 된다.
가상 호스트 설정은 <tt>server</tt> 블럭에 들어간다. 첫 번째 블럭은 <tt>www.example.com</tt>으로 접속한 경우 <tt>example.com</tt>으로 넘겨주는 것이다. 반대의 경우라면 <tt>server_name</tt> 지시자의 값만 바꾸면 된다.
== 참고 ==
== 참고 ==
31번째 줄: 31번째 줄:
{{Nginx}}
{{Nginx}}
[[분류:위키노트/공유]]
[[분류:위키노트/공유]]
[[분류:웹]]
[[분류:위키노트/웹]]
[[분류:서버]]
[[분류:위키노트/서버]]
[[분류:위키노트/소프트웨어 설정]]{{퍼온문서|위키노트|{{#invoke:string|replace|{{PAGENAME}}|위키노트:|}}}}[[분류:위키노트에서 가져온 문서]]
[[분류:위키노트/소프트웨어 설정]]{{퍼온문서|위키노트|{{#invoke:string|replace|{{PAGENAME}}|위키노트:|}}}}[[분류:위키노트에서 가져온 문서]]

2022년 5월 7일 (토) 15:20 기준 최신판

Nginx에서는 가상 호스트 설정을 /etc/nginx/conf.d 디렉토리 아래에 호스트별로 저장한다. 이렇게 하는 것이 하나의 파일로 설정할 때보다는 유지보수하는데 편할 수도 있다. 아래 내용은 가상 호스트 example.com의 설정 파일인 /etc/nginx/conf.d/example.conf의 내용이다.

server {
    listen      80;
    server_name www.example.com;
    return 301  $scheme://example.com$request_uri;
}server {
    listen      80 default_server;
    server_name example.com;
    root        /var/www/example;
    index       index.html index.php;
    charset     utf-8;
    access_log  /var/log/nginx/example-access.log  main;
    #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;
    }
    # deny access to .htaccess files, if Apache's document root concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

가상 호스트 설정은 server 블럭에 들어간다. 첫 번째 블럭은 www.example.com으로 접속한 경우 example.com으로 넘겨주는 것이다. 반대의 경우라면 server_name 지시자의 값만 바꾸면 된다.

참고

이 작은숲 문서의 출처는 위키노트의 위키노트/Nginx 가상 호스트 설정 문서입니다.