바뀜

둘러보기로 가기 검색하러 가기
3,775 바이트 추가됨 ,  2021년 5월 1일 (토) 18:12
새 문서: == Nginx 설치 및 설정 == <pre> $ sudo apt install nginx nginx-extras libnginx-mod-http-geoip libnginx-mod-http-fancyindex </pre> === nginx에서 디렉터리 목록 나열을...
== Nginx 설치 및 설정 ==

<pre>
$ sudo apt install nginx nginx-extras libnginx-mod-http-geoip libnginx-mod-http-fancyindex
</pre>


=== nginx에서 디렉터리 목록 나열을 허용하기(fancyindex 이용) ===
/etc/nginx/sites-available/default 파일에서 ‘location /’ 항목에 아래 초록색 내용을 추가합니다.
fancyindex를 이용하면 웹에서 파일과 디렉터리 목록을 예쁘게 볼 수 있습니다.

<syntaxhighlight lang="diff">
(.. 생략 ..)
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.


#autoindex on; # 디렉터리 목록을 나열한다.
#autoindex_exact_size off;

+ fancyindex on; # 디렉터리 목록을 나열한다.(fancyindex 사용)
+ fancyindex_exact_size off;

try_files $uri $uri/ =404;
}
(.. 생략 ..)
</syntaxhighlight>

=== nginx에서 해외 아이피 차단. 국내 아이피만 접속 허용(geoip 이용) ===

==== /etc/nginx/nginx.conf 파일 수정 ====
/etc/nginx/nginx.conf 파일에 아래 초록색으로 표시한 내용을 추가합니다.

<syntaxhighlight lang="diff">
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
+ # 우리나라를 제외한 해외 아이피를 모두 차단함.
+ geoip_country /usr/share/GeoIP/GeoIP.dat;
+ map $geoip_country_code $allowed_country {
+ default no;
+ KR yes;
+ }

##
# Basic Settings
##

sendfile on;
(..생략..)

</syntaxhighlight>

==== /etc/nginx/sites-available/default 파일 수정 ====

<syntaxhighlight lang="diff">
(..생략..)
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.

fancyindex on;
fancyindex_exact_size off;

+ if ($allowed_country = no) {
+ return 444;
+ }
+ try_files $uri $uri/ /index.html;

- #try_files $uri $uri/ =404;
}
(..생략..)
</syntaxhighlight>

==== Nginx 재시작 ====
<pre>
$ sudo systemctl restart nginx
</pre>

== rsync 설치 ==
<pre>
$ sudo apt install rsync
</pre>

== MRTG 설치 및 설정 <ref>https://www.youtube.com/watch?v=ftutyWqzRCs</ref>==
<pre>
$ sudo apt install snmpd snmp mrtg
</pre>


/etc/snmp/snmpd.conf 파일을 아래처럼 수정합니다.

<syntaxhighlight lang="diff">
(..생략..)
-#rocommunity public localhost
+rocommunity public localhost
(..생략..)
</syntaxhighlight>


snmpd를 재시작합니다.

<pre>
$ systemctl restart snmpd
</pre>


mrtg 디렉터리를 생성합니다.

<pre>
$ sudo mkdir /data/mrtg
</pre>


mrtg.cfg 파일을 백업합니다.

<pre>
$ sudo cp /etc/mrtg.cfg /etc/mrtg.cfg.bak
</pre>


/etc/mrtg 파일을 편집합니다.

<syntaxhighlight lang="diff">
(..생략..)
- #WorkDir: /var/www/mrtg
+ WorkDir: /data/mrtg
(..생략..)
+ # to get bits instead of bytes and graphs growing to the right
+ Options[_]: growright, bits
(..생략..)
</syntaxhighlight>


<pre>
cfgmaker public@localhost > /etc/mrtg.cfg
</pre>


MRTG의 index.html 파일을 생성합니다.
<pre>
indexmaker /etc/mrtg.cfg > /data/mrtg/index.html
</pre>


MRTG 데이터는 /data/mrtg에 저장됩니다. 이 데이터를 웹에서 보여주고자 /var/www/mrtg로 심볼릭링크를 걸었습니다.
<pre>
$ ln -s /data/mrtg/ /var/www/mrtg
</pre>

이제 MRTG의 인덱스 페이지를 볼 수 있습니다. 저의 경우는 http://mirror.debianusers.or.kr/mrtg/ 에서 MRTG의 인덱스 페이지를 확인할 수 있습니다.

== 참고 ==

둘러보기 메뉴