This commit is contained in:
root 2024-07-26 00:36:17 +03:00
commit 93b0b25852
8 changed files with 150 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
ssl/*

106
0010-cache.conf Normal file
View File

@ -0,0 +1,106 @@
server {
listen 80;
server_name cdn.playemulator.io www.playemulator.io static.playemulator.io images.playemulator.io;
root /srv/playemulator/data;
index index.html index.htm;
# access_log /srv/steamcache/logs/access.log steamcache-default;
# error_log /srv/steamcache/logs/error.log;
proxy_temp_path /tmp/nginx/ 1 2;
resolver 8.8.8.8;
# location / {
# try_files $uri @mirror;
# # access_log /srv/steamcache/logs/access.log steamcache-local;
# }
location / {
proxy_next_upstream error timeout http_404;
proxy_pass http://$host$request_uri;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Mirror-Upstream-Status $upstream_status;
add_header X-Mirror-Upstream-Response-Time $upstream_response_time;
add_header X-Mirror-Status $upstream_cache_status;
add_header Host $host;
# access_log /srv/steamcache/logs/access.log steamcache-other;
}
location @mirror {
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_next_upstream error timeout http_404;
proxy_pass https://$host;
#$request_uri;
proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
# add_header X-Mirror-Upstream-Status $upstream_status;
# add_header X-Mirror-Upstream-Response-Time $upstream_response_time;
# add_header X-Mirror-Status $upstream_cache_status;
# access_log /srv/steamcache/logs/access.log steamcache-remote;
}
}
server {
listen 443 ssl http2;
proxy_cache default_cache;
server_name cdn.playemulator.io www.playemulator.io static.playemulator.io images.playemulator.io;
# ssl_certificate www.example.com.chained.crt;
# ssl_certificate_key www.example.com.key;
ssl_certificate /etc/ssl/local/cache.chained.crt;
ssl_certificate_key /etc/ssl/local/cache.key;
root /srv/playemulator/data;
index index.html index.htm;
# access_log /srv/steamcache/logs/access.log steamcache-default;
# error_log /srv/steamcache/logs/error.log;
proxy_temp_path /tmp/nginx/ 1 2;
resolver 8.8.8.8;
# location /uploads/games/ {
# try_files $uri @mirror;
# access_log /srv/playemulator/logs/access.log steamcache-local;
# }
location / {
proxy_next_upstream error timeout http_404;
proxy_pass https://$host$request_uri;
proxy_ssl_verify off;
proxy_ssl_server_name on;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_buffering on;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Mirror-Upstream-Status $upstream_status;
add_header X-Mirror-Upstream-Response-Time $upstream_response_time;
add_header X-Mirror-Status $upstream_cache_status;
add_header Host $host;
# access_log /srv/steamcache/logs/access.log steamcache-other;
}
location @mirror {
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_next_upstream error timeout http_404;
proxy_pass https://$host$request_uri;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
add_header X-Mirror-Upstream-Status $upstream_status;
add_header X-Mirror-Upstream-Response-Time $upstream_response_time;
add_header X-Mirror-Status $upstream_cache_status;
# access_log /srv/steamcache/logs/access.log steamcache-remote;
}
}

27
Makefile Normal file
View File

@ -0,0 +1,27 @@
all:
echo OK
install:
mkdir /srv/playemulator/data -p
chown www-data:www-data -R /srv/playemulator/data
cp -vf 0010-cache.conf /etc/nginx/sites-available/
cp -vf cache-dir.conf /etc/nginx/conf.d/
cd /etc/nginx/sites-enabled && ln -s ../sites-available/0010-cache.conf;true
install-cert:
mkdir /etc/ssl/local -p
cat ssl/cert.pem ssl/chain.pem > /etc/ssl/local/cache.chained.crt
cat ssl/key.pem > /etc/ssl/local/cache.key
start:
systemctl start nginx
reload:
systemctl reload nginx
restart: stop start
stop:
systemctl stop nginx
enable:
systemctl enable nginx
disable:
systemctl disable nginx

3
README.md Normal file
View File

@ -0,0 +1,3 @@
##
* <https://arstechnica.com/gaming/2017/01/building-a-local-steam-caching-server-to-ease-the-bandwidth-blues/>

9
cache-dir.conf Normal file
View File

@ -0,0 +1,9 @@
proxy_cache_path /srv/playemulator/cache levels=1:2 keys_zone=default_cache:10m max_size=2g
inactive=120m use_temp_path=off;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 302 129600m;
#proxy_cache_methods GET HEAD POST;
log_format steamcache-local '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" LOCAL';

3
decrypt-key.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
openssl rsa -in ssl/key.pem.encrypted -out ssl/key.pem

0
ssl/.placeholder Normal file
View File

1
test.sh Normal file
View File

@ -0,0 +1 @@
curl 'https://static.playemulator.io/uploads/games/202011/kawasaki-superbike-challenge.smc?ver=104' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Origin: https://load.retroemulator.com' -H 'Connection: keep-alive' -H 'Referer: https://load.retroemulator.com/' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: cross-site' -H 'TE: trailers' --output /dev/null -k