|
|
|
|
|
|
|
|
worker_processes auto; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
events { |
|
|
worker_connections 1024; |
|
|
} |
|
|
|
|
|
http { |
|
|
include /etc/nginx/mime.types; |
|
|
default_type application/octet-stream; |
|
|
|
|
|
|
|
|
client_body_temp_path /tmp/client_body_temp 1 2; |
|
|
proxy_temp_path /tmp/proxy_temp 1 2; |
|
|
fastcgi_temp_path /tmp/fastcgi_temp 1 2; |
|
|
uwsgi_temp_path /tmp/uwsgi_temp 1 2; |
|
|
scgi_temp_path /tmp/scgi_temp 1 2; |
|
|
|
|
|
|
|
|
access_log /dev/stdout; |
|
|
error_log /dev/stderr notice; |
|
|
|
|
|
sendfile on; |
|
|
tcp_nopush on; |
|
|
tcp_nodelay on; |
|
|
keepalive_timeout 65; |
|
|
types_hash_max_size 2048; |
|
|
|
|
|
|
|
|
upstream target_huggingface_space { |
|
|
|
|
|
server ${TARGET_HOSTNAME_NO_SCHEME}:443; |
|
|
|
|
|
} |
|
|
|
|
|
server { |
|
|
listen 7860 default_server; |
|
|
server_name _; |
|
|
|
|
|
|
|
|
proxy_hide_header Link; |
|
|
proxy_hide_header X-Canonical-Url; |
|
|
proxy_hide_header X-Powered-By; |
|
|
proxy_hide_header Server; |
|
|
|
|
|
|
|
|
|
|
|
proxy_hide_header X-Frame-Options; |
|
|
proxy_hide_header Content-Security-Policy; |
|
|
|
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN" always; |
|
|
add_header Content-Security-Policy "frame-ancestors 'self' *; script-src 'self' 'unsafe-inline' https: data: blob:; object-src 'none'; base-uri 'self';" always; |
|
|
add_header X-Content-Type-Options "nosniff" always; |
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always; |
|
|
|
|
|
|
|
|
|
|
|
sub_filter_types text/html; |
|
|
sub_filter_once on; |
|
|
|
|
|
|
|
|
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>"; |
|
|
|
|
|
|
|
|
sub_filter '<head>' '<head>$console_disabler_script_full'; |
|
|
|
|
|
|
|
|
location / { |
|
|
proxy_pass https://target_huggingface_space; |
|
|
|
|
|
|
|
|
proxy_set_header Host ${TARGET_HOSTNAME_NO_SCHEME}; |
|
|
proxy_set_header X-Real-IP $remote_addr; |
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
|
proxy_set_header X-Forwarded-Proto $scheme; |
|
|
proxy_set_header X-Forwarded-Host $host; |
|
|
proxy_set_header X-Forwarded-Port $server_port; |
|
|
|
|
|
proxy_http_version 1.1; |
|
|
proxy_set_header Connection ""; |
|
|
proxy_buffering on; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
location = /ws { |
|
|
proxy_pass https://target_huggingface_space/ws; |
|
|
proxy_http_version 1.1; |
|
|
proxy_set_header Upgrade $http_upgrade; |
|
|
proxy_set_header Connection "upgrade"; |
|
|
proxy_set_header Host ${TARGET_HOSTNAME_NO_SCHEME}; |
|
|
proxy_set_header X-Real-IP $remote_addr; |
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
|
proxy_set_header X-Forwarded-Proto $scheme; |
|
|
|
|
|
|
|
|
proxy_connect_timeout 7d; |
|
|
proxy_send_timeout 7d; |
|
|
proxy_read_timeout 7d; |
|
|
} |
|
|
} |
|
|
} |