사용자 도구

사이트 도구


miniserver:xenial

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
miniserver:xenial [2016/06/06 15:22] – [PHP 7.0] changwoominiserver:xenial [2018/01/02 02:34] (현재) – [Torrent] 잘못된 스크립트 수정 changwoo
줄 140: 줄 140:
  
 ==== Dokuwiki ==== ==== Dokuwiki ====
 +
 <code - vhost-wiki.conf> <code - vhost-wiki.conf>
 # Nginx Configuration # Nginx Configuration
 +
 +# 아래 설정은 https 적용 이후 http -> https 이동에 사용됨.
 +server {
 +    listen     80;
 +    server_name     wiki.changwoo.pe.kr;
 +    return          301 https://$server_name$request_uri;
 +}
  
 server { server {
줄 194: 줄 202:
 </code> </code>
  
 +nginx라면 복구 이후 멋진 URL에서 .htaccess 방식을 선택해야 문서가 올바르게 보인다.
 ==== WordPress ==== ==== WordPress ====
 이 녀석은 조금 복잡하다. 이 녀석은 조금 복잡하다.
줄 270: 줄 279:
  
 <code - vhost-wordpress.conf> <code - vhost-wordpress.conf>
 +
 +# 아래 설정은 https 적용 이후 http -> https 이동에 사용됨.
 +server {
 +    listen     80;
 +    server_name     wiki.changwoo.pe.kr;
 +    return          301 https://$server_name$request_uri;
 +}
 +
 server { server {
  server_name blog.changwoo.pe.kr;  server_name blog.changwoo.pe.kr;
줄 277: 줄 294:
  index index.php;  index index.php;
  
- include /media/storage/www-data/conf.d/wordpress-restrictions.conf;+        # wp-login.php, wp-admin 접근을 IP로 제한 (단, wp-ajax.php는 AJAX를 활용해야 하므로 허용) 
 +        location ~ ^/(wp-admin(?!/admin-ajax\.php)|wp-login.php) { 
 +            allow 192.168.0.0/24; 
 +            deny all; 
 +            include snippets/fastcgi-php.conf; 
 +     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
 +        }
  
 + include /media/storage/www-data/conf.d/wordpress-restrictions.conf;
  include /media/storage/www-data/conf.d/wordpress.conf;  include /media/storage/www-data/conf.d/wordpress.conf;
 } }
줄 285: 줄 309:
  
 ==== Ampache ==== ==== Ampache ====
 +그동안 모바일 기기에서 제대로 재생이 되지 않는 문제가 있었다가, nginx 설정을 변경해 줌으로써 해결하였다. 아래는 성공한 설정 텍스트. [[https://github.com/ampache/ampache/wiki/Installation#nginx|이 쪽의 설정]]을 가져와 문제가 되는 부분을 적절히 수정한 것.
 +
 +<code nginx vhost-ampache.conf>
 +server {
 +
 +    # listen to
 +    #listen  [::]:used_port; #ssl; ipv6 optional with ssl enabled
 +    listen   80; #ssl; ipv4 optional with ssl enabled
 +
 +    server_name stream.changwoo.pe.kr;
 +    charset utf-8;
 +
 +    # Logging, error_log mode [notice] is necessary for rewrite_log on,
 +    # (very usefull if rewrite rules do not work as expected)
 +
 +       error_log       /var/log/ampache/error.log; #notice;
 +       access_log      /var/log/ampache/access.log;
 +       # rewrite_log     on;
 +
 +    # only optional for ssl encryption enabled: Path to certificate/key
 +
 +        # ssl_certificate         /etc/ssl/certs/cert.crt;
 +        # ssl_certificate_key     /etc/ssl/private/key.key;
 +
 +    root  /media/storage/www-data/changwoo.pe.kr/ampache;
 +    index index.php;
 +
 +    # Somebody said this helps, in my setup it doesn't prevent temporary saving in files
 +    proxy_max_temp_file_size 0;
 +
 +    # Rewrite rule for Subsonic backend
 +    if ( !-d $request_filename ) {
 +        rewrite ^/rest/(.*).view$ /rest/index.php?action=$1 last;
 +        rewrite ^/rest/fake/(.+)$ /play/$1 last;
 +    }
 +
 +    # Rewrite rule for Channels
 +    if (!-d $request_filename){
 +      rewrite ^/channel/([0-9]+)/(.*)$ /channel/index.php?channel=$1&target=$2 last;
 +    }
 +
 +    # Beautiful URL Rewriting
 +    # rewrite ^/play/ssid/(.*)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&name=$5 last;
 +    # rewrite ^/play/ssid/(.*)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&name=$7 last;
 +    # rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&player=$7&name=$8 last;
 +    # rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/transcode_to/(w+)/bitrate/([0-9]+)/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&transcode_to=$7&bitrate=$8&player=$9&name=$10 last;
 +
 +    # Subsonic Apps (not working!)
 +    # rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/content_length/(.*)/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&content_length=$7&player=$8&name=$9 redirect;
 +    # rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/bitrate/([0-9]+)/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&bitrate=$7&player=$8&name=$9 redirect;
 +    # rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&player=$7&name=$8 redirect;
 +
 +    # the following line was needed for me to get downloads of single songs to work
 +    rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/action/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4action=$5&name=$6 last;
 +    
 +    location /play/ssid {
 +        if (!-e $request_filename) {
 +            # Subsonic Apps
 +            rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/content_length/(.*)/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&content_length=$7&player=$8&name=$9 last;
 +            rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/bitrate/([0-9]+)/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&bitrate=$7&player=$8&name=$9 last;
 +            rewrite ^/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/player/(.*)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&player=$7&name=$8 last;
 +            break;
 +        }
 +    }
 +
 +    location /play {
 +        if (!-e $request_filename) {
 +            rewrite ^/play/art/([^/]+)/([^/]+)/([0-9]+)/thumb([0-9]*)\.([a-z]+)$ /image.php?object_type=$2&object_id=$3&auth=$1;
 +            break;
 +        }
 +
 +        rewrite ^/([^/]+)/([^/]+)(/.*)?$ /play/$3?$1=$2;
 +        rewrite ^/(/[^/]+|[^/]+/|/?)$ /play/index.php last;
 +        break;
 +    }
 +
 +   location /rest {
 +      limit_except GET POST {
 +         deny all;
 +      }
 +   }
 +
 +   location ^~ /bin/ {
 +      deny all;
 +      return 403;
 +   }
 +
 +   location ^~ /config/ {
 +      deny all;
 +      return 403;
 +   }
 +
 +   location / {
 +      limit_except GET POST HEAD{
 +         deny all;
 +      }
 +   }
 +
 +   location ~ ^/.*.php {
 +        try_files $uri = 404;
 +        fastcgi_index index.php;
 +
 +    # sets the timeout for requests in [s] , 60s are normally enough
 +        fastcgi_read_timeout 600s;
 +
 +        include fastcgi_params;
 +        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 +
 +    # Mitigate HTTPOXY https://httpoxy.org/
 +        fastcgi_param HTTP_PROXY "";
 +
 +    # has to be set to on if encryption (https) is used:
 +        # fastcgi_param HTTPS on;
 +
 +        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 +
 +    # chose as your php-fpm is configured to listen on
 +        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
 +        # fastcgi_pass 127.0.0.1:8000/;
 +   }
 +
 +   # Rewrite rule for WebSocket
 +   location /ws {
 +        rewrite ^/ws/(.*) /$1 break;
 +        proxy_http_version 1.1;
 +        proxy_set_header Upgrade $http_upgrade;
 +        proxy_set_header Connection "upgrade";
 +        proxy_set_header Host $host;
 +        proxy_pass http://127.0.0.1:8100/;
 +   }
 +}
 +
 +</code>
 ==== Python 계열 세팅 ==== ==== Python 계열 세팅 ====
 내가 운용 중인 모든 애플리케이션은 Python3로 작성되어 있으니, 그 쪽으로 세팅을 맞춘다. 내가 운용 중인 모든 애플리케이션은 Python3로 작성되어 있으니, 그 쪽으로 세팅을 맞춘다.
줄 331: 줄 488:
  
 === uWSGI === === uWSGI ===
 +
 +앱이 하나일 때는 아래와 같이 간단하게 master로 돌렸다.
 <code - miniserver-apps.ini> <code - miniserver-apps.ini>
 [uwsgi] [uwsgi]
줄 355: 줄 514:
 daemonize = <path-to-log> daemonize = <path-to-log>
 </code> </code>
 +
 +그러나 복수의 앱을 운영해야 할 시점이 생기자 엡퍼러(emperor) 모드가 필요해졌다. 엠퍼러 모드는 간단하게 이렇게 쓸 수 있다.
 +
 +<code - uwsgi-emperor.ini>
 +uid=owner
 +
 +daemonize=<path-to-log>
 +
 +emperor=<path-to-store-vassals>
 +
 +</code>
 +
 +<path-to-store-vassals>에는 그룹으로 돌릴 ini 파일들을 넣으면 된다. 즉 miniserver-apps.ini 파일 같은 것을 그대로 이 디렉토리에 넣으면 되는데, 이 때 주의할 점은 몇몇 설정들은 이미 엠퍼러에서 진행되었으므로 삭제해야 한다. 예를 들어 miniserver-apps.ini에서 demonize, uid 같은 설정값은 에러를 낼 수 있다.
  
 === rc.local === === rc.local ===
줄 369: 줄 541:
 uwsgi --reload /tmp/project-master.pid uwsgi --reload /tmp/project-master.pid
 kill -HUP `cat /tmp/project-master.pid` kill -HUP `cat /tmp/project-master.pid`
 +killall -s INT uwsgi
 </code> </code>
  
줄 391: 줄 564:
 create mask = 0644 create mask = 0644
 directory mask = 0755 directory mask = 0755
 +</code>
 +
 +심볼릭 링크를 추가하기 위해 다음과 같은 세팅을 주었다((http://unix.stackexchange.com/questions/5120/how-do-you-make-samba-follow-symlink-outside-the-shared-path))
 +<code>
 +[global]
 +allow insecure wide links = yes
 +
 +[share]
 +follow symlinks = yes
 +wide links = yes
 </code> </code>
  
줄 509: 줄 692:
 <code - deluge-daemon> <code - deluge-daemon>
 #!/bin/sh #!/bin/sh
-### BEGIN INIT INFO 
-# Provides:          deluge-daemon 
-# Required-Start:    $local_fs $remote_fs 
-# Required-Stop:     $local_fs $remote_fs 
-# Should-Start:      $network 
-# Should-Stop:       $network 
-# Default-Start:     2 3 4 5 
-# Default-Stop:      0 1 6 
-# Short-Description: Daemonized version of deluge and webui. 
-# Description:       Starts the deluge daemon with the user specified in 
-#                    /etc/default/deluge-daemon. 
-### END INIT INFO 
- 
-# Author: Adolfo R. Brandes  
-# Updated by: Jean-Philippe "Orax" Roemer 
- 
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
-DESC="Deluge Daemon" 
-NAME1="deluged" 
-NAME2="deluge" 
-DAEMON1=/usr/bin/deluged 
-DAEMON1_ARGS="-d -c /media/storage/changwoo/.config/deluge -L info -l /media/storage/changwoo/.config/deluge/deluge.log"             # Consult `man deluged` for more options 
-DAEMON2=/usr/bin/deluge-web 
-DAEMON2_ARGS=""               # Consult `man deluge-web` for more options 
-PIDFILE1=/var/run/$NAME1.pid 
-PIDFILE2=/var/run/$NAME2.pid 
-UMASK=022                     # Change this to 0 if running deluged as its own user 
-PKGNAME=deluge-daemon 
-SCRIPTNAME=/etc/init.d/$PKGNAME 
- 
-# Exit if the package is not installed 
-[ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0 
- 
-# Read configuration variable file if it is present 
-[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME 
- 
-# Load the VERBOSE setting and other rcS variables 
-[ -f /etc/default/rcS ] && . /etc/default/rcS 
- 
-# Define LSB log_* functions. 
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 
-. /lib/lsb/init-functions 
- 
-if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ] 
-then 
-   log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it." 
-   exit 0 
-fi 
- 
-if [ -z "$DELUGED_USER" ] 
-then 
-    log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME." 
-    exit 0 
-fi 
- 
-# 
-# Function to verify if a pid is alive 
-# 
-is_alive() 
-{ 
-   pid=`cat $1` > /dev/null 2>&1 
-   kill -0 $pid > /dev/null 2>&1 
-   return $? 
-} 
- 
-# 
-# Function that starts the daemon/service 
-# 
-do_start() 
-{ 
-   # Return 
-   #   0 if daemon has been started 
-   #   1 if daemon was already running 
-   #   2 if daemon could not be started 
- 
-   is_alive $PIDFILE1 
-   RETVAL1="$?" 
- 
-   if [ $RETVAL1 != 0 ]; then 
-       rm -f $PIDFILE1 
-       start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile \ 
-       --exec $DAEMON1 --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON1_ARGS 
-       RETVAL1="$?" 
-   else 
-       is_alive $PIDFILE2 
-       RETVAL2="$?" 
-       [ "$RETVAL2" = "0" -a "$RETVAL1" = "0" ] && return 1 
-   fi 
- 
-   is_alive $PIDFILE2 
-   RETVAL2="$?" 
- 
-   if [ $RETVAL2 != 0 ]; then 
-        sleep 2 
-        rm -f $PIDFILE2 
-        start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile \ 
-        --exec $DAEMON2 --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON2_ARGS 
-        RETVAL2="$?" 
-   fi 
-   [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2 
-} 
- 
-# 
-# Function that stops the daemon/service 
-# 
-do_stop() 
-{ 
-   # Return 
-   #   0 if daemon has been stopped 
-   #   1 if daemon was already stopped 
-   #   2 if daemon could not be stopped 
-   #   other if a failure occurred 
- 
-   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2 
-   RETVAL2="$?" 
-   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1 
-   RETVAL1="$?" 
-   [ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2 
- 
-   rm -f $PIDFILE1 $PIDFILE2 
- 
-   [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1 
-} 
- 
-case "$1" in 
-  start) 
-   [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1" 
-   do_start 
-   case "$?" in 
-      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
-      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
-   esac 
-   ;; 
-  stop) 
-   [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1" 
-   do_stop 
-   case "$?" in 
-      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
-      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
-   esac 
-   ;; 
-  restart|force-reload) 
-   log_daemon_msg "Restarting $DESC" "$NAME1" 
-   do_stop 
-   case "$?" in 
-     0|1) 
-      do_start 
-      case "$?" in 
-         0) log_end_msg 0 ;; 
-         1) log_end_msg 1 ;; # Old process is still running 
-         *) log_end_msg 1 ;; # Failed to start 
-      esac 
-      ;; 
-     *) 
-        # Failed to stop 
-      log_end_msg 1#!/bin/sh 
 ### BEGIN INIT INFO ### BEGIN INIT INFO
 # Provides:          deluge-daemon # Provides:          deluge-daemon
줄 821: 줄 848:
         # Failed to stop         # Failed to stop
       log_end_msg 1       log_end_msg 1
-      ;; 
-   esac 
-   ;; 
-  *) 
-   echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 
-   exit 3 
-   ;; 
-esac 
- 
-: 
       ;;       ;;
    esac    esac
줄 884: 줄 901:
 </code> </code>
  
 +
 +===== Resilio-Sync =====
 +[[https://www.resilio.com/ | Resilio-Sync ]]로 비트토렌트 방식의 싱크. [[project:btsyncforrpi | 라즈베리 파이에서 BitTorrentSync로 데이터 동기화하기 ]] 같은 문서로도 작성한 바가 있다. 이게 이름이 바뀌었다.
 +
 +가정용은 무료이니 나같이 그냥 비디오 디렉토리 공유하는 수준에서는 괜찮은 선택인 것 같다.
 +
 +deb 패키지가 제공되니 깔아 주면 그만이다. service resilio-sync start 명령으로 실행하면 되는데, 변경은 다음과 같은 명령으로
 +<code bash>
 +$ sudo systemctl edit resilio-sync.service 
 +
 +[Service]
 +User=changwoo
 +Group=changwoo
 +PIDFile=
 +PIDFile=/home/changwoo/.config/resilio-sync/sync.pid
 +ExecStartPre=
 +ExecStartPre=/bin/mkdir -p /home/changwoo/.config/resilio-sync
 +ExecStartPre=/bin/chown -R changwoo:changwoo /home/changwoo/.config/resilio-sync
 +ExecStart=
 +ExecStart=/usr/bin/rslsync --config /home/changwoo/.config/resilio-sync/config.json
 +</code>
 +
 +systemctl edit 명령은 파일 자체를 변경하는 것이 아니라 overriding 하는 방식이다.그리고 override 할 때 기존 명령어는 한번 비워주는 작업이 필요하다. 그래서 "''ExexStart=''" 같은 라인이 생기는 것이다. 저것이 없으면 에러.
 +
 +<code bash>
 +$ sudo systemctl cat resilio-sync.service
 +
 +[Unit]
 +Description=Resilio Sync service
 +Documentation=https://help.getsync.com/
 +After=network.target network-online.target
 +
 +[Service]
 +Type=forking
 +User=rslsync
 +Group=rslsync
 +UMask=0002
 +Restart=on-failure
 +PermissionsStartOnly=true
 +PIDFile=/var/run/resilio-sync/sync.pid
 +ExecStartPre=/bin/mkdir -p /var/run/resilio-sync
 +ExecStartPre=/bin/chown -R rslsync:rslsync /var/run/resilio-sync
 +ExecStart=/usr/bin/rslsync --config /etc/resilio-sync/config.json
 +
 +[Install]
 +WantedBy=multi-user.target
 +
 +# /etc/systemd/system/resilio-sync.service.d/override.conf
 +[Service]
 +User=changwoo
 +Group=changwoo
 +PIDFile=
 +PIDFile=/home/changwoo/.config/resilio-sync/sync.pid
 +ExecStartPre=
 +ExecStartPre=/bin/mkdir -p /home/changwoo/.config/resilio-sync
 +ExecStartPre=/bin/chown -R changwoo:changwoo /home/changwoo/.config/resilio-sync
 +ExecStart=
 +ExecStart=/usr/bin/rslsync --config /home/changwoo/.config/resilio-sync/config.json
 +
 +
 +</code>
 +
 +이렇게 덧붙여지는 것을 참고하자.
  
  
 +===== SSL 설비 =====
 +이제는 필수로 구비하자. Let's Encrypt가 있다. 아래의 가이드를 따라하면 어렵지 않다.
 +  * https://certbot.eff.org/#ubuntuxenial-nginx
 +  * http://riseshia.github.io/2016/10/16/certbot-let-s-encrypt.html
 +3개월마다 갱신해야 하는데, 나는 아직 자동 갱신을 하지는 않았다. 나중에 확인하고 달아 보도록 하자.
  
  
miniserver/xenial.1465226521.txt.gz · 마지막으로 수정됨: 2016/06/06 15:22 저자 changwoo

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki