# Default localhost VirtualHost for testing
<VirtualHost *:80>
    ServerAdmin admin@media-trust.com
    DocumentRoot "/var/www/html3"
    ServerName winlogic.site
    ErrorLog /var/log/apache2/localhost_error.log
    CustomLog /var/log/apache2/localhost_access.log combined
    <Directory "/var/www/html3">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html index.php
    </Directory>
</VirtualHost>

# SSL vhosts are managed separately under /etc/apache2/sites-available
# Enable them after certs are issued (a2ensite llmapi-ssl n8n-ssl).

<VirtualHost *:80>
    ServerAdmin admin@media-trust.com
    DocumentRoot "/var/www/html3/web/brnch"
    ServerName brnch.winlogic.site
    ErrorLog /var/log/apache2/brnch_error.log
    CustomLog /var/log/apache2/brnch_access.log combined
    <Directory "/var/www/html3/web/brnch">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html index.php
    </Directory>
    Alias /error/ "/var/www/html3/web/error/"
    ErrorDocument 403 /error/index.html
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@media-trust.com
    ServerName hdqrs.winlogic.site
    DocumentRoot "/var/www/html3/web/hdqrs"
    ErrorLog /var/log/apache2/hdqrs_error.log
    CustomLog /var/log/apache2/hdqrs_access.log combined
    <Directory "/var/www/html3/web/hdqrs">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html index.php
    </Directory>
    Alias /error/ "/var/www/html3/web/error/"
    ErrorDocument 403 /error/index.html
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@media-trust.com
    ServerName ddds.winlogic.site
    DocumentRoot "/var/www/html3/web/ddds"
    ErrorLog /var/log/apache2/ddds_error.log
    CustomLog /var/log/apache2/ddds_access.log combined
    <Directory "/var/www/html3/web/ddds">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html index.php
    </Directory>
    Alias /error/ "/var/www/html3/web/error/"
    ErrorDocument 403 /error/index.html
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@media-trust.com
    ServerName tracer-app.winlogic.site
    DocumentRoot "/var/www/html3/web/tracer"
    ErrorLog /var/log/apache2/tracer_error.log
    CustomLog /var/log/apache2/tracer_access.log combined
    <Directory "/var/www/html3/web/tracer">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html index.php
    </Directory>
    Alias /error/ "/var/www/html3/web/error/"
    ErrorDocument 403 /error/index.html
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin admin@media-trust.com
  ServerName llmapi.px-wing.com
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPassReverse / http://172.17.0.1:8787/
  ErrorLog  /var/log/apache2/api_pxwing_error.log
  CustomLog /var/log/apache2/api_pxwing_access.log combined
</VirtualHost>


 
<VirtualHost *:80>
    ServerName n8n.px-wing.com
    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "http"
    # Exclude ACME challenge from proxy so Let's Encrypt can fetch it
    ProxyPass        /.well-known/acme-challenge !
    ProxyPass        / http://172.17.0.1:5678/ keepalive=On timeout=600
    ProxyPassReverse / http://172.17.0.1:5678/
</VirtualHost>


<VirtualHost *:80>
    ServerName llmadmin.px-wing.com
    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "http"
    # Exclude ACME challenge from proxy so Let's Encrypt can fetch it
    ProxyPass        /.well-known/acme-challenge !
    ProxyPass        / http://172.17.0.1:6006/ keepalive=On timeout=600
    ProxyPassReverse / http://172.17.0.1:6006/
    ErrorLog  /var/log/apache2/llmadmin_error.log
    CustomLog /var/log/apache2/llmadmin_access.log combined
</VirtualHost>


<VirtualHost *:443>
    ServerName llmadmin.px-wing.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/llmadmin.px-wing.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/llmadmin.px-wing.com/privkey.pem

    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "https"

    ProxyPass        / http://172.17.0.1:6006/ keepalive=On timeout=600
    ProxyPassReverse / http://172.17.0.1:6006/

    ErrorLog  /var/log/apache2/llmadmin_ssl_error.log
    CustomLog /var/log/apache2/llmadmin_ssl_access.log combined
</VirtualHost>


<VirtualHost *:443>
    ServerAdmin admin@media-trust.com
    ServerName llmapi.px-wing.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/llmapi.px-wing.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/llmapi.px-wing.com/privkey.pem

    ProxyRequests Off
    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "https"

    ProxyPass        / http://172.17.0.1:8787/ keepalive=On timeout=600
    ProxyPassReverse / http://172.17.0.1:8787/

    ErrorLog  /var/log/apache2/api_pxwing_ssl_error.log
    CustomLog /var/log/apache2/api_pxwing_ssl_access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerName n8n.px-wing.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/n8n.px-wing.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/n8n.px-wing.com/privkey.pem

    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "https"

    # --- WebSocketサポートの追加 ---
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*) ws://172.17.0.1:5678/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*) http://172.17.0.1:5678/$1 [P,L]

    ProxyPass        / http://172.17.0.1:5678/ keepalive=On timeout=600
    ProxyPassReverse / http://172.17.0.1:5678/

    ErrorLog  /var/log/apache2/n8n_ssl_error.log
    CustomLog /var/log/apache2/n8n_ssl_access.log combined
</VirtualHost>
