Create cmx-im.work.conf

This commit is contained in:
cmx 2022-08-15 01:34:29 -04:00
parent b8064e6f93
commit ef795998e6
1 changed files with 151 additions and 0 deletions

151
nginx_conf/cmx-im.work.conf Normal file
View File

@ -0,0 +1,151 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
map $http_cf_connecting_ip $x_real_ip_ip {
default $http_cf_connecting_ip;
'' $remote_addr;
}
proxy_cache_path /var/cache/nginx/cmx-im.work levels=1:2 keys_zone=CACHE_cmx-im.work:10m inactive=2d max_size=5g;
map $http_origin $cmxim_work_origin {
default $http_origin;
https://cmx-im.work https://m.cmx.im;
}
map $http_referrer $cmxim_work_referrer {
default '';
~^https://cmx-im.work/(?<referrer_path>.*)$ https://m.cmx.im/$referrer_path;
}
map $request_uri $cmxim_work_content_security_policy {
default "CSP_rules";
~^/api.* '';
~^/system.* '';
}
server {
listen 80;
listen [::]:80;
server_name cmx-im.work;
if ($host = cmx-im.work) {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
set $origin_domain m.cmx.im;
server_name cmx-im.work;
ssl_certificate /etc/letsencrypt/live/cmx-im.work/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cmx-im.work/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
keepalive_timeout 70;
sendfile on;
client_max_body_size 80m;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4;
resolver_timeout 5s;
location / {
try_files $uri @proxy;
}
location @proxy {
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
proxy_ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
proxy_redirect https://$origin_domain https://$server_name;
sub_filter '//$origin_domain' '//$server_name';
sub_filter '<a class="selected" href="https://$origin_domain' '<a class="selected" href="https://$server_name';
sub_filter '<a target="sidekiq" href="https://$origin_domain' '<a target="sidekiq" href="https://$server_name';
sub_filter '<a target="pghero" href="https://$origin_domain' '<a target="pghero" href="https://$server_name';
sub_filter '<a data-method="delete" href="https://$origin_domain/auth/sign_out">' '<a data-method="delete" href="https://$server_name/auth/sign_out">';
sub_filter '"streaming_api_base_url":"wss://$origin_domain"' '"streaming_api_base_url":"wss://$server_name"';
sub_filter 'https://m.cmx.im/avatars/original/missing.png' 'https://cmx-im.work/avatars/original/missing.png';
sub_filter 'https://$origin_domain/system/' 'https://$server_name/system/';
sub_filter_once off;
sub_filter_types application/json;
proxy_hide_header Alt-Svc;
proxy_hide_header Content-Security-Policy;
proxy_set_header Origin $cmxim_work_origin;
proxy_set_header Referer $cmxim_work_referrer;
proxy_set_header Host $origin_domain;
proxy_set_header X-Real-IP $x_real_ip_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Accept-Encoding "";
proxy_pass_header Server;
proxy_cookie_domain $origin_domain $server_name;
proxy_pass https://$origin_domain;
proxy_buffering on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cache CACHE_cmx-im.work;
proxy_cache_valid 200 7d;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
add_header X-Cached $upstream_cache_status;
add_header X-Robots-Tag "noindex, nofollow";
add_header Content-Security-Policy $cmxim_work_content_security_policy;
tcp_nodelay on;
}
location ~ inbox$ {
return 307 https://$origin_domain$request_uri;
}
location /.well-known {
return 307 https://$origin_domain$request_uri;
}
location /proxy {
return 307 https://$origin_domain$request_uri;
}
location /api/v1/streaming {
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
proxy_ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
proxy_set_header Host $origin_domain;
proxy_set_header X-Real-IP $x_real_ip_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Proxy "";
proxy_pass https://$origin_domain;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
tcp_nodelay on;
}
}