Create nginx.conf.template
Browse files- nginx.conf.template +110 -0
nginx.conf.template
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# nginx.conf.template
|
| 2 |
+
|
| 3 |
+
worker_processes auto;
|
| 4 |
+
|
| 5 |
+
# مسیر فایل PID در اینجا تنظیم نمیشود، چون از طریق -g در entrypoint.sh پاس داده میشود.
|
| 6 |
+
# pid /var/run/nginx.pid; # این خط غیرفعال است
|
| 7 |
+
|
| 8 |
+
events {
|
| 9 |
+
worker_connections 1024;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
http {
|
| 13 |
+
include /etc/nginx/mime.types;
|
| 14 |
+
default_type application/octet-stream;
|
| 15 |
+
|
| 16 |
+
# مسیرهای موقت برای Nginx، مطمئن شوید /tmp قابل نوشتن است (که معمولا هست)
|
| 17 |
+
client_body_temp_path /tmp/client_body_temp 1 2;
|
| 18 |
+
proxy_temp_path /tmp/proxy_temp 1 2;
|
| 19 |
+
fastcgi_temp_path /tmp/fastcgi_temp 1 2;
|
| 20 |
+
uwsgi_temp_path /tmp/uwsgi_temp 1 2;
|
| 21 |
+
scgi_temp_path /tmp/scgi_temp 1 2;
|
| 22 |
+
|
| 23 |
+
# لاگها به stdout و stderr هدایت میشوند تا در لاگهای کانتینر نمایش داده شوند
|
| 24 |
+
access_log /dev/stdout;
|
| 25 |
+
error_log /dev/stderr notice; # میتوانید سطح لاگ را به warn یا error تغییر دهید
|
| 26 |
+
|
| 27 |
+
sendfile on;
|
| 28 |
+
tcp_nopush on;
|
| 29 |
+
tcp_nodelay on;
|
| 30 |
+
keepalive_timeout 65;
|
| 31 |
+
types_hash_max_size 2048;
|
| 32 |
+
# server_tokens off; # هدر Server را با جزئیات نسخه Nginx مخفی میکند (اختیاری)
|
| 33 |
+
|
| 34 |
+
upstream target_huggingface_space {
|
| 35 |
+
# ${TARGET_HOSTNAME_NO_SCHEME} توسط entrypoint.sh از TARGET_HF_SPACE_URL استخراج میشود
|
| 36 |
+
server ${TARGET_HOSTNAME_NO_SCHEME}:443;
|
| 37 |
+
# keepalive 16; # برای بهبود عملکرد با استفاده مجدد از کانکشنها (اختیاری)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
server {
|
| 41 |
+
listen 7860 default_server;
|
| 42 |
+
server_name _; # به هر هاستنیمی پاسخ میدهد
|
| 43 |
+
|
| 44 |
+
# --- مهم: این بخش هدرهای مشخصی را از پاسخ سرور هدف حذف میکند ---
|
| 45 |
+
proxy_hide_header Link; # این هدر URL کنونیکال را فاش میکند
|
| 46 |
+
proxy_hide_header X-Canonical-Url; # برای اطمینان، اگر هدر دیگری هم بود
|
| 47 |
+
proxy_hide_header X-Powered-By; # اطلاعات سرور بکاند را مخفی میکند
|
| 48 |
+
proxy_hide_header Server; # اطلاعات سرور بکاند را مخفی میکند (اگر upstream خودش تنظیم نکند)
|
| 49 |
+
# --- پایان بخش مهم ---
|
| 50 |
+
|
| 51 |
+
# هدرهای امنیتی که شما اضافه کرده بودید، حفظ شدهاند
|
| 52 |
+
proxy_hide_header X-Frame-Options; # از پاسخ بکاند حذف شود تا add_header ما اعمال شود
|
| 53 |
+
proxy_hide_header Content-Security-Policy; # از پاسخ بکاند حذف شود تا add_header ما اعمال شود
|
| 54 |
+
|
| 55 |
+
# اضافه کردن هدرهای امنیتی توسط پروکسی
|
| 56 |
+
add_header X-Frame-Options "SAMEORIGIN" always; # یا "DENY" اگر نمیخواهید در هیچ iframe ای نمایش داده شود
|
| 57 |
+
add_header Content-Security-Policy "frame-ancestors 'self' *; script-src 'self' 'unsafe-inline' https: data: blob:; object-src 'none'; base-uri 'self';" always;
|
| 58 |
+
add_header X-Content-Type-Options "nosniff" always;
|
| 59 |
+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
| 60 |
+
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # اگر HTTPS همیشه فعال است
|
| 61 |
+
|
| 62 |
+
# تنظیمات sub_filter برای تزریق اسکریپت (فقط برای محتوای text/html)
|
| 63 |
+
sub_filter_types text/html;
|
| 64 |
+
sub_filter_once on; # فقط اولین تطابق را جایگزین میکند (مهم برای <head>)
|
| 65 |
+
|
| 66 |
+
# اسکریپت کاملتر برای غیرفعال کردن تمام متدهای console (همانطور که شما داشتید)
|
| 67 |
+
set $console_disabler_script_full "<script id='hf-proxy-console-disabler-full'>\n(function() {\n if (window.hfProxyConsoleFullyDisabled) return;\n window.hfProxyConsoleFullyDisabled = true;\n var preservedConsoleLogForProxy;\n try {\n if (window.console && typeof window.console.log === 'function') {\n preservedConsoleLogForProxy = window.console.log.bind(window.console);\n } else {\n preservedConsoleLogForProxy = function(){};\n }\n } catch (e) {\n preservedConsoleLogForProxy = function(){};\n }\n var noop = function() {};\n var consoleMethods = [\n 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',\n 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline',\n 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'\n ];\n var newConsoleReplacement = {};\n for (var i = 0; i < consoleMethods.length; i++) {\n newConsoleReplacement[consoleMethods[i]] = noop;\n }\n try {\n if (typeof window.console !== 'undefined') {\n Object.defineProperty(window, 'console', {\n value: newConsoleReplacement,\n writable: false,\n configurable: false\n });\n } else {\n Object.defineProperty(window, 'console', {\n value: newConsoleReplacement,\n writable: false,\n configurable: false\n });\n }\n } catch (e) {\n window.console = newConsoleReplacement;\n }\n})();\n</script>";
|
| 68 |
+
|
| 69 |
+
# تزریق اسکریپت غیرفعالکننده کنسول بلافاصله بعد از تگ <head>
|
| 70 |
+
sub_filter '<head>' '<head>$console_disabler_script_full';
|
| 71 |
+
# sub_filter '</head>' '$console_disabler_script_full</head>'; # جایگزین اگر <head> صفات داشته باشد
|
| 72 |
+
|
| 73 |
+
location / {
|
| 74 |
+
proxy_pass https://target_huggingface_space; # از upstream تعریف شده استفاده میکند
|
| 75 |
+
|
| 76 |
+
# تنظیم هدرهای مهم برای ارسال به سرور هدف
|
| 77 |
+
proxy_set_header Host ${TARGET_HOSTNAME_NO_SCHEME}; # بسیار مهم: هاست اسپیس اصلی
|
| 78 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 79 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 80 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 81 |
+
proxy_set_header X-Forwarded-Host $host; # هاست پروکسی فعلی (مثلا your-proxy-space.hf.space)
|
| 82 |
+
proxy_set_header X-Forwarded-Port $server_port; # پورت پروکسی فعلی
|
| 83 |
+
|
| 84 |
+
proxy_http_version 1.1;
|
| 85 |
+
proxy_set_header Connection ""; # برای مدیریت بهتر کانکشنها توسط Nginx
|
| 86 |
+
proxy_buffering on; # بافر کردن پاسخ از بکاند میتواند عملکرد را بهبود بخشد
|
| 87 |
+
|
| 88 |
+
# تایماوتها (اختیاری، مقادیر پیشفرض معمولا مناسب هستند)
|
| 89 |
+
# proxy_connect_timeout 60s;
|
| 90 |
+
# proxy_send_timeout 60s;
|
| 91 |
+
# proxy_read_timeout 60s;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
location = /ws { # مسیر WebSocket (اگر اسپیس شما از WebSocket استفاده میکند)
|
| 95 |
+
proxy_pass https://target_huggingface_space/ws; # مطمئن شوید مسیر /ws در اسپیس هدف صحیح است
|
| 96 |
+
proxy_http_version 1.1;
|
| 97 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 98 |
+
proxy_set_header Connection "upgrade";
|
| 99 |
+
proxy_set_header Host ${TARGET_HOSTNAME_NO_SCHEME}; # هاست اسپیس اصلی
|
| 100 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 101 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 102 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 103 |
+
|
| 104 |
+
# تایماوتهای طولانیتر برای WebSocket
|
| 105 |
+
proxy_connect_timeout 7d;
|
| 106 |
+
proxy_send_timeout 7d;
|
| 107 |
+
proxy_read_timeout 7d;
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
}
|