server {
    listen 80;
    server_name  _;
    return 301 https://$host$request_uri;
}

server {
    listen 8080;
    server_name  _;
    root /var/www/xcontact;
    location / {
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        root           /var/www/xcontact;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
    }

    location /xcontact-rest/ {
        index  index.html index.htm index.php;
        try_files $uri /xcontact-rest/index.php$is_args$args;
    }

    location /agente4 {
	index index.html;
	try_files $uri $uri/ /agente4/index.html;
    }
}

server {
    #listen 443 ssl http2 default_server;
    listen 443 ssl;
    server_name  _;
    ssl_certificate "/etc/asterisk/keys/asterisk.pem";
    ssl_certificate_key "/etc/asterisk/keys/asterisk.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    root /var/www/xcontact;
    location / {
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        root           /var/www/xcontact;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
    }

    location /phppgadmin/ {
        index  index.html index.htm index.php;
        allow 172.30.25.0/24;
	allow 172.30.51.0/24;
        deny all;
    }

    location /xcontact-rest/ {
        index  index.html index.htm index.php;
        try_files $uri /xcontact-rest/index.php$is_args$args;
    }

    location /agente4 {
        index index.html;
        try_files $uri $uri/ /agente4/index.html;
    }
}

server {
    listen 8003 ssl;
    ssl_certificate "/etc/asterisk/keys/asterisk.pem";
    ssl_certificate_key "/etc/asterisk/keys/asterisk.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    server_name _;
    location / {
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 8004 ssl;
    ssl_certificate "/etc/asterisk/keys/asterisk.pem";
    ssl_certificate_key "/etc/asterisk/keys/asterisk.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    server_name _;
    location / {
        proxy_pass http://localhost:8001;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 3003 ssl;
    ssl_certificate "/etc/asterisk/keys/asterisk.pem";
    ssl_certificate_key "/etc/asterisk/keys/asterisk.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    server_name _;
    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 8011 ssl;
    ssl_certificate "/etc/asterisk/keys/asterisk.pem";
    ssl_certificate_key "/etc/asterisk/keys/asterisk.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    server_name _;
    location / {
        proxy_pass http://localhost:8010;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
