user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 65535;
	# multi_accept on;
}

#stream {
#    server {
#        listen 27017;
#        proxy_connect_timeout 1s;
#        proxy_timeout 3s;
#        proxy_pass stream_mongo_backend;
#    }
#    
#    upstream stream_mongo_backend {
#      server 127.0.0.1:27020;
#    }
#}

http {
    client_max_body_size 150M;
	charset utf-8;
	proxy_cache_path /data/nginx/cache keys_zone=STATIC:10m loader_threshold=300 loader_files=200;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

	sendfile on;
	tcp_nopush on;
	types_hash_max_size 2048;
	# server_tokens off;
	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;
	include /etc/nginx/mime.types;
	default_type application/octet-stream;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;
	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	gzip on;
    gzip_proxied any;
    gzip_comp_level 4;
    # gzip_types text/css application/javascript image/svg+xml;
	gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;

    upstream test { server 127.0.0.1:8002; }
    upstream centrifugo { server 127.0.0.1:8003; }
    upstream cast { server 127.0.0.1:55392; }

    server {
        server_name ws.twodev.cc;

        location /centrifugo/ {
            rewrite ^/centrifugo/(.*)        /$1 break;
            proxy_pass http://centrifugo;
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
        }

        location /centrifugo/connection {
            rewrite ^/centrifugo(.*)        $1 break;
            proxy_pass http://centrifugo;
            proxy_buffering off;
            keepalive_timeout 65;
            proxy_read_timeout 60s;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header Host $http_host;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    
        location /music {
            proxy_pass http://cast;
            proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host;
        }

        location /test {
            proxy_pass http://test;
            proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host;
        }
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/ws.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/ws.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name api.twodev.cc;

        location /centrifugo/ { proxy_pass http://localhost:8003/; }
        location /ivbo/ { proxy_pass http://localhost:4001/; }
        location /helper/ { proxy_pass http://localhost:4002/; }
        # location /ai/ { proxy_pass http://localhost:4003/; }
        # location /upload/ { proxy_pass http://localhost:4004/; }
        location /topvuz/ { proxy_pass http://localhost:4005/; }
        location /fences/ { proxy_pass http://localhost:4006/; }
        location /mab/ { proxy_pass http://localhost:4007/; }
        location /via/ { proxy_pass http://localhost:4008/; }
        location /academy/ { proxy_pass http://localhost:4009/; }
        location /mokeup/ { proxy_pass http://localhost:4010/; }
        location /fishmalek/ { proxy_pass http://localhost:4011/; }
        location /idontread/ { proxy_pass http://localhost:4012/; }
        location /round/ { proxy_pass http://localhost:4013/; }
        location /raduga/biller/ { proxy_pass http://localhost:4014/; }
        # location /music/ { proxy_pass http://localhost:55392/; }
        location /medicine/ { proxy_pass http://localhost:8083/;}

        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/api.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/api.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

	server {
        server_name twodev.cc;
        #set $port 3001;
  
        error_page 500 502 503 504 /custom_50x.html;
        location = /custom_50x.html {
            root /mnt/m2/cdn/nginx502page;
            internal;
        }

		#include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
		server_name viatutor.ru;
        set $port 3002;
		include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/viatutor.ru/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/viatutor.ru/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name mkrk.cc;
        set $port 3003;
        include dockerized_nextjs;
    
        # auth_basic "волчара";
        # auth_basic_user_file /etc/nginx/.htpasswd;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/mkrk.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/mkrk.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name academy.twodev.cc;
		set $port 3004;
		include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/academy.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/academy.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name ivbo.twodev.cc;
		set $port 3005;
        include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/ivbo.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/ivbo.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name symm.twodev.cc;
        set $port 3007;
		include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/symm.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/symm.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        listen 80;
        server_name ml.twodev.cc;
        set $port 3009;
        include dockerized_nextjs;
    }

    server {
        server_name idontread.ru www.idontread.ru;
        set $port 3012;
        include dockerized_nextjs;
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/idontread.ru/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/idontread.ru/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        listen 80;
        server_name www.mokeup.ru mokeup.ru;
        set $port 3011;
        auth_basic "волчара";
        auth_basic_user_file /etc/nginx/.htpasswd;
        include dockerized_nextjs;
    }

    server {
        server_name tgweb.twodev.cc;
        root /mnt/m2/tgweb;

        location / {
            index index.html;
        }
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/tgweb.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/tgweb.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        server_name cdn.twodev.cc;
        root /mnt/m2/cdn;

        location / {
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
        }
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/cdn.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/cdn.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
		server_name storage.twodev.cc;
		root /mnt/m2/public_storage;

		location / {
			autoindex on;
			autoindex_exact_size off;
			autoindex_localtime on;
		}
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/storage.twodev.cc/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/storage.twodev.cc/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

	server {
		server_name storage.viatutor.ru;
		root /mnt/m2/storage;

		#root /mnt/m2/storage_page;
		#index index.php;
		
		#location ~ \.php$ {
		#	include snippets/fastcgi-php.conf;
		#	fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
		#}

		location / {
			autoindex on;
			autoindex_exact_size off;
			autoindex_localtime on;
			#try_files $uri $uri/ =404;
			auth_basic "волчара";
			auth_basic_user_file /etc/nginx/hash/.storage;
		}
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/storage.viatutor.ru/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/storage.viatutor.ru/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }
        
	server {
    if ($host = twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = academy.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name academy.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = api.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name api.twodev.cc;

        listen 80;
    return 404; # managed by Certbot


}

server {
    if ($host = ml.twodev.cc) {
        return 301 http://$host$request_uri;
    } # managed by Certbot


        server_name ml.twodev.cc;

        listen 443;
    return 404; # managed by Certbot


}

    server {
    if ($host = cdn.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name cdn.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = ivbo.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name ivbo.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = m.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name m.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = storage.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


		server_name storage.twodev.cc;

        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = symm.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name symm.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = ws.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name ws.twodev.cc;

        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = quiz.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name quiz.twodev.cc;

        listen 80;
    return 404; # managed by Certbot


}

	server {
    if ($host = viatutor.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
		server_name viatutor.ru;
    return 404; # managed by Certbot


}

	server {
    if ($host = storage.viatutor.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


		server_name storage.viatutor.ru;
    
        listen 80;
    return 404; # managed by Certbot


}   
    server {
    if ($host = fish.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name fish.twodev.cc;

     listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = mkrk.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name mkrk.cc;
    return 404; # managed by Certbot


}

    server {
    if ($host = sync.mkrk.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name sync.mkrk.cc;
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = docker.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name docker.twodev.cc;
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = idontread.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name idontread.ru www.idontread.ru;
    return 404; # managed by Certbot


}

    server {
    if ($host = tgweb.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name tgweb.twodev.cc;
    
        listen 80;
    return 404; # managed by Certbot


}

    server {
    if ($host = tgweb.cherry4xo.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name tgweb.cherry4xo.ru;
    return 404; # managed by Certbot


}

    server {
    if ($host = cloud.mkrk.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name cloud.mkrk.cc;
    return 404; # managed by Certbot


}

    server {
    if ($host = cdn.fish.twodev.cc) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name cdn.fish.twodev.cc;
    return 404; # managed by Certbot


}

    server {
    if ($host = med.cherry4xo.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name med.cherry4xo.ru;
    listen 80;
    return 404; # managed by Certbot


}}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
#
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}
