OS : Cenots 7.x
NGINX : 1.17.8
Awstats : 7.8
nginx 1.17.8 install -> https://xinet.kr/?p=2765
1. 다운로드 ( 다운로드는 공식 홈페이지에서 다운로드 가능 https://awstats.sourceforge.io/ ) 및 폴더 변경
1 2 3 4 5 |
[root@xinet ~]# wget https://prdownloads.sourceforge.net/awstats/awstats-7.8.tar.gz [root@xinet ~]# tar xvfz awstats-7.8.tar.gz [root@xinet ~]# mv awstats-7.8 /usr/local/awstats |
2. 사용자 환경 config 파일 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@xinet ~]# cd /usr/local/awstats/tools/ [root@xinet tools]# perl awstats_configure.pl ### 처음 설치하는 경우 config 파일 생성할거냐 물어보면 Y Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? Y 입력 ### 도메인 입력하랴면 자신의 도메인 입력 Your web site, virtual server or profile name: xinet.kr ### 기본 config 파일 저장 위치를 /etc/awstats 저장할거면 확인하면 엔터 Default: /etc/awstats Directory path to store config file(s) (Enter for default): > 엔터 ## 엔터 |
3. awstats 환경설정 파일 수정 ( geoip 설치되어 있어야함 없으면 Geoip 부분 주석처리) / 설치 yum -y install Geo-*
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@localhost tools]# vi /etc/awstats/awstats.xinet.kr.conf ### 아래내용으로 수정 LogFile="/usr/local/nginx/logs/access.log" LogFormat=1 DirData="/usr/local/awstats" LoadPlugin="graphgooglechartapi" LoadPlugin="geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat" LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoIPCity.dat" |
4. 이제 모든 설정이 완료되었으므로 로그 파일을 awstats 에 맞게 파싱을 해보자
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@localhost tools]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=awstats.xinet.kr.conf -update Create/Update database for config "/etc/awstats/awstats.awstats.xinet.kr.conf" by AWStats version 7.7 (build 20180105) From data in log file "/usr/local/nginx/logs/tlstest3.xinet.kr_access.log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 1464 Found 20 dropped records, Found 0 comments, Found 0 blank records, Found 11 corrupted records, Found 0 old records, Found 1433 new qualified records. |
5. awstats-fcgi.php 파일 복사
1 |
[root@localhost tools]# cp -a /usr/local/awstats/tools/nginx/awstats-fcgi.php /usr/local/awstats/wwwroot/cgi-bin/fcgi.php |
6. awstats.conf 파일 생성 ( nginx.conf에서 include / http 통신되게 설정 )
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
[root@localhost tools]# vi /usr/local/nginx/conf/awstats.conf server { listen 80; server_name awstats.xinet.kr; root /usr/local/awstats/wwwroot; index index.html; # Restrict access #auth_basic "Restricted"; #auth_basic_user_file /usr/local/htpasswd.pass; # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/ location /classes/ { alias /usr/local/awstats/wwwroot/classes/; } location /css/ { alias /usr/local/awstats/wwwroot/css/; } location /icon/ { alias /usr/local/awstats/wwwroot/icon/; } location /awstats-icon/ { alias /usr/local/awstats/wwwroot/icon/; } location /awstatsicons/ { alias /usr/local/awstats/wwwroot/icon/; } location /js/ { alias /usr/local/awstats/wwwroot/js/; } # Dynamic stats. location ~ ^/cgi-bin/(awredir|awstats)\.pl { gzip off; fastcgi_pass unix:/usr/local/php-fpm/var/run/php-fpm.sock; #fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/fcgi.php; fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot/$fastcgi_script_name; fastcgi_param X_SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; } } |
여기서 통신을 https로 할 경우 아래 config 내용으로
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
server { listen 80; server_name awstats.xinet.kr; root /usr/local/awstats/wwwroot; index index.html; ### HTTP -> HTTPS Redirect location / { return 301 https://awstats.xinet.kr$request_uri; } } ### HTTPS server { listen 443 ssl http2; server_name awstats.xinet.kr; access_log logs/awstats.xinet.kr_access.log main; ssl_certificate /etc/letsencrypt/live/awstats.xinet.kr/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/awstats.xinet.kr/privkey.pem; ssl_prefer_server_ciphers on; keepalive_timeout 60; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_early_data on; ssl_protocols TLSv1.3 TLSv1.2; ssl_ecdh_curve X25519:P-256:P-384; ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256; proxy_set_header Early-Data $ssl_early_data; root /usr/local/awstats/wwwroot; index index.html; ### NGINX START # Restrict access #auth_basic "Restricted"; #auth_basic_user_file /usr/local/awstats/.htpasswd ; # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/ location /classes/ { alias /usr/local/awstats/wwwroot/classes/; } location /css/ { alias /usr/local/awstats/wwwroot/css/; } location /icon/ { alias /usr/local/awstats/wwwroot/icon/; } location /awstats-icon/ { alias /usr/local/awstats/wwwroot/icon/; } location /awstatsicons/ { alias /usr/local/awstats/wwwroot/icon/; } location /js/ { alias /usr/local/awstats/wwwroot/js/; } # Dynamic stats. location ~ ^/cgi-bin/(awredir|awstats)\.pl { gzip off; fastcgi_pass unix:/usr/local/php-fpm/var/run/php-fpm.sock; #fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/fcgi.php; fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot/$fastcgi_script_name; fastcgi_param X_SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; } } |
7. nginx.conf 파일 include
1 2 3 4 5 |
[root@localhost tools]# vi /usr/local/nginx/conf/nginx.conf ### 하단에 include awstats.conf; |
8. nginx.conf 검사 확인 및 서비스 재시작
1 2 3 4 5 6 |
[root@localhost tools]# nginx -t nginx: the configuration file /usr/local/nginx/etc/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/etc/nginx.conf test is successful [root@localhost tools]# systemctl restart nginx |
9. 웹페이지에서 확인 -> https://awstats.xinet.kr/cgi-bin/awstats.pl?config=/awstats.xinet.kr.conf
10. 크론에 등록 자동으로 업데이트 될수 있게 구성
1 2 3 4 5 6 7 8 9 10 |
[root@xinet ~]# crontab -e ### awstats update */10 * * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=awstats.xinet.kr.conf -update ### CRON 재시작 [root@xinet ~]# systemctl restart crond |
11. 만약 awstats 페이지에 로그인 (암호)으로 변경하려면 htpasswd 명령어를 이용하펴 패스워드를 지정하면 된다
(htpasswd 명령어는 httpd24u-tools 에 포함되어 있다 명령어가 존재 하지 않는다면 yum -y intall httpd-tools 설치)
만약 httpd-tools를 설치하기 귀찮다면 openssl 명령어로 사용하면 된다 -> 하단 15번 내용 참고)
1 2 3 4 |
[root@xinet cgi-bin]# htpasswd -c /usr/local/awstats/.htpasswd admin New password: Re-type new password: Adding password for user admin |
1 2 |
[root@localhost tools]# cat /usr/local/awstats/.htpasswd admin:$apr1$RZzuj2aE$bkY8zu7Mw7X3CrBuvCSjn1 |
12. awstats.conf 파일에 인증을 사용할 수 있게 변경
1 2 3 4 5 6 |
[root@localhost tools]# vi /usr/local/nginx/conf/awstats.conf # Restrict access auth_basic "Restricted"; auth_basic_user_file /usr/local/awstats/.htpasswd; |
13. nginx 재시작
1 |
[root@localhost tools]# systemctl restart nginx |
14. 웹페이지에서 인증 암호 창 확인
15. 만약 htpasswd 명령어를 사용하지 않는다면 openssl 명령어를 이용해서 진행할 수 있다
1 2 3 4 |
[root@localhost tools]# openssl passwd -1 Password: Verifying - Password: $1$VeEJNEwE$9j8qM9NBm0ETZw8kTCyUt0 |
해당 값을 파일에 지정하면 된다
1 2 3 |
[root@localhost tools]# vi /usr/local/awstats/.htpasswd admin:$1$VeEJNEwE$9j8qM9NBm0ETZw8kTCyUt0 |
무료인증서 등록 방법
1 |
[root@xinet /usr/local/nginx/conf]# certbot certonly --webroot --agree-tos -m jsh@email.com -w /usr/local/awstats/wwwroot/ -d awstats.xinet.kr |
–webroot : webroot 방식으로 ssl 인증서 발급
-m : 이메일 입력
-w : webroot 방식의 인증을 위해 홈 디렉토리 지정
-d : 인증서 발급 도메인 입력
1 2 3 4 5 6 7 |
[root@xinet ~]# ls -l /etc/letsencrypt/live/awstats.xinet.kr/ -rw-r--r-- 1 root root 692 9월 11 11:42 README lrwxrwxrwx 1 root root 45 9월 11 11:42 cert.pem -> ../../archive/awstats.xinet.kr/cert1.pem lrwxrwxrwx 1 root root 46 9월 11 11:42 chain.pem -> ../../archive/awstats.xinet.kr/chain1.pem lrwxrwxrwx 1 root root 50 9월 11 11:42 fullchain.pem -> ../../archive/awstats.xinet.kr/fullchain1.pem lrwxrwxrwx 1 root root 48 9월 11 11:42 privkey.pem -> ../../archive/awstats.xinet.kr/privkey1.pem |