diff --git a/tasks/configure_redirector.yml b/tasks/configure_redirector.yml index 3fdec53..999d3ab 100644 --- a/tasks/configure_redirector.yml +++ b/tasks/configure_redirector.yml @@ -70,6 +70,10 @@ group: root when: zero_logs | bool +- name: Set subdomain value explicitly + set_fact: + redirector_subdomain: "cdn" + - name: Configure NGINX for C2 redirection template: src: "../templates/redirector-site.conf.j2" @@ -108,7 +112,76 @@ creates: /etc/letsencrypt/live/{{ redirector_subdomain }}.{{ domain }}/fullchain.pem when: domain != "example.com" +- name: Test NGINX configuration + command: nginx -t + register: nginx_config_test + ignore_errors: true + +- name: Debug NGINX configuration test results if failed + debug: + var: nginx_config_test.stderr_lines + when: nginx_config_test.rc != 0 + +- name: Ensure NGINX configurations are valid + block: + - name: Fix NGINX configuration if test failed + copy: + content: | + server { + listen 80; + listen [::]:80; + server_name cdn.{{ domain }}; + + # Root directory + root /var/www/html; + index index.html; + + # Primary location for legitimate traffic + location / { + try_files $uri $uri/ =404; + } + + # Special URI patterns for C2 traffic + location /ajax/ { + proxy_pass http://{{ c2_ip }}:8888; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + # Static resources + location ~ ^/static/(css|js|images)/.*\.(css|js|png|jpg|jpeg|gif|ico)$ { + proxy_pass http://{{ c2_ip }}:8888; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } + + # Catch-all server block + server { + listen 80 default_server; + listen [::]:80 default_server; + + # Redirect unknown traffic + return 301 https://www.google.com; + } + dest: /etc/nginx/sites-available/default + mode: '0644' + owner: root + group: root + when: nginx_config_test.rc != 0 + when: nginx_config_test.rc != 0 + - name: Restart NGINX systemd: name: nginx - state: restarted \ No newline at end of file + state: restarted + register: nginx_restart + ignore_errors: true + +- name: Verify NGINX is running + service: + name: nginx + state: started + when: nginx_restart is failed \ No newline at end of file diff --git a/templates/redirector-index.html.j2 b/templates/redirector-index.html.j2 index 00910cf..9176dba 100644 --- a/templates/redirector-index.html.j2 +++ b/templates/redirector-index.html.j2 @@ -3,7 +3,7 @@
-Enterprise Content Delivery Network
This server is part of our global content delivery network, optimizing digital asset delivery for enterprise applications. Our CDN provides fast, reliable, and secure content distribution across our global network.
-This is a private service. Unauthorized access is prohibited.
-Content cached and distributed across multiple geographic locations for minimum latency.
-Enterprise-grade protection against distributed denial of service attacks.
-Automatic compression and format optimization for images, scripts, and styles.
-If you're a client requiring access to our CDN services, please contact your account representative.
- Contact Sales +This server is part of our global content delivery network.