Raspberry PiにSimple NuGet Serverを構築する

提供: MonoBook
ナビゲーションに移動 検索に移動


必要なパッケージを入れる[編集 | ソースを編集]

Simple NuGet Serverの公式サイトに書いてあるパッケージではちょっと足りない模様。

apt-get update
apt-get install git
apt-get install nginx 
apt-get install php-fpm php-zip php-bz2 php-xml php-json php-sqlite3 php-common php-mbstring php-intl php-readline php-bcmath php-curl

Simple NuGet Serverを落としてくる[編集 | ソースを編集]

Simple NuGet Serverソースコードgithubから頂いてくる。

cd /var/www/
git clone https://github.com/Daniel15/simple-nuget-server.git

ソースコードを手に入れたら、NuGetパッケージをPUSHするときに使うAPIキー(パスワード)を書き換える。 本家本元のフルバージョンのNuGet Serverはユーザーごとに発行されるものだが、 Simple NuGet Serverは個人利用しか想定していないので1個しか設定できない。 だがそれがいい。

cd simple-nuget-server
vi inc/config.php
Config::$apiKey = '書き換える';

wwwディレクトリのパーミッションを書き換える。

chown -R www-data /var/www/simple-nuget-server

PHP-FPMの設定を変更する[編集 | ソースを編集]

/etc/php/7.3/fpm/pool.d/www.conf

nugetパッケージの保管場所のパーミッションに合わせる。

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

dynamicが必要なほど需要はないし、リソースの限られたラズパイではstaticが望ましい。というかnginxは普通のレンタルサーバーでの運用でもstaticの方が安定している。

pm = static
pm.max_children = 1

nginxの設定を変更する[編集 | ソースを編集]

/etc/nginx/sites-enabled/default

server {
	server_name _;
    
	listen 80 default_server;
	#listen [::]:80 default_server;

	root /var/www/simple-nuget-server/public; 

	index index.php index.html index.htm;

    // 64MBまで送受信できるようにする。
    // php.iniのupload_max_filesizeとpost_max_sizeも書き換える。
	client_max_body_size 64M;

    // リライトルール
    rewrite ^/$ /index.php;
    rewrite ^/\$metadata$ /metadata.xml;
    rewrite ^/Search\(\)/\$count$ /count.php;
    rewrite ^/Search\(\)$ /search.php;
    rewrite ^/Packages\(\)$ /search.php;
    rewrite ^/Packages\(Id='([^']+)',Version='([^']+)'\)$ /findByID.php?id=$1&version=$2;
    rewrite ^/GetUpdates\(\)$ /updates.php;
    rewrite ^/FindPackagesById\(\)$ /findByID.php;
    # NuGet.exe sometimes uses two slashes (//download/blah)
    rewrite ^//?download/([^/]+)/([^/]+)$ /download.php?id=$1&version=$2;
    rewrite ^/([^/]+)/([^/]+)$ /delete.php?id=$1&version=$2;

    # NuGet.exe adds /api/v2/ to URL when the server is at the root
    rewrite ^/api/v2/package/$ /index.php;
    rewrite ^/api/v2/package/([^/]+)/([^/]+)$ /delete.php?id=$1&version=$2;

    # Used with X-Accel-Redirect
    location /packagefiles {
            internal;
            root /var/www/simple-nuget-server/;
    }

    location ~ \.php?$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }

    location = /index.php {
        dav_methods PUT DELETE;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

        # PHP doesn't parse request body for PUT requests, so fake a POST.
        fastcgi_param REQUEST_METHOD POST;
        fastcgi_param HTTP_X_METHOD_OVERRIDE $request_method;
    }
}

関連項目[編集 | ソースを編集]