apache.conf 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <VirtualHost *:80>
  2. ServerName localhost
  3. DocumentRoot /var/www/html/frontend/dist
  4. # Serve Vue.js frontend (SPA)
  5. <Directory /var/www/html/frontend/dist>
  6. AllowOverride All
  7. Require all granted
  8. # Handle Vue.js routing - redirect all non-file requests to index.html
  9. RewriteEngine On
  10. RewriteCond %{REQUEST_FILENAME} !-f
  11. RewriteCond %{REQUEST_FILENAME} !-d
  12. RewriteRule . /index.html [L]
  13. </Directory>
  14. # Handle PHP API endpoints
  15. <Directory "/var/www/html/api">
  16. AllowOverride All
  17. Require all granted
  18. Options -Indexes
  19. </Directory>
  20. # Enable CORS for API endpoints
  21. <Directory "/var/www/html/api">
  22. # Set CORS headers based on origin
  23. SetEnvIfNoCase Origin "^https://inventory\.valavuo\.net$" CORS_ALLOW_ORIGIN
  24. SetEnvIfNoCase Origin "^http://localhost(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  25. SetEnvIfNoCase Origin "^http://127\.0\.0\.1(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  26. Header set Access-Control-Allow-Origin "%{CORS_ALLOW_ORIGIN}e" env=CORS_ALLOW_ORIGIN
  27. Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
  28. Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
  29. Header set Access-Control-Allow-Credentials "true"
  30. # Fallback for development
  31. Header set Access-Control-Allow-Origin "*" env=!CORS_ALLOW_ORIGIN
  32. </Directory>
  33. # Handle OPTIONS requests for CORS
  34. <FilesMatch "\.php$">
  35. SetEnvIf Request_Method "OPTIONS" CORs
  36. </FilesMatch>
  37. <IfModule mod_headers.c>
  38. # Dynamic CORS based on origin
  39. SetEnvIfNoCase Origin "^https://inventory\.valavuo\.net$" CORS_ALLOW_ORIGIN
  40. SetEnvIfNoCase Origin "^http://localhost(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  41. SetEnvIfNoCase Origin "^http://127\.0\.0\.1(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  42. Header always set Access-Control-Allow-Origin "%{CORS_ALLOW_ORIGIN}e" env=CORS_ALLOW_ORIGIN
  43. Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" env=CORs
  44. Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" env=CORs
  45. Header always set Access-Control-Allow-Credentials "true" env=CORs
  46. # Fallback for development
  47. Header always set Access-Control-Allow-Origin "*" env=!CORS_ALLOW_ORIGIN
  48. </IfModule>
  49. # API endpoint routing
  50. Alias /api /var/www/html/api
  51. # Handle uploads directory
  52. Alias /uploads /var/www/html/uploads
  53. <Directory "/var/www/html/uploads">
  54. AllowOverride All
  55. Require all granted
  56. Options -Indexes
  57. # Set CORS headers based on origin
  58. SetEnvIfNoCase Origin "^https://inventory\.valavuo\.net$" CORS_ALLOW_ORIGIN
  59. SetEnvIfNoCase Origin "^http://localhost(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  60. SetEnvIfNoCase Origin "^http://127\.0\.0\.1(:[0-9]+)?$" CORS_ALLOW_ORIGIN
  61. Header set Access-Control-Allow-Origin "%{CORS_ALLOW_ORIGIN}e" env=CORS_ALLOW_ORIGIN
  62. Header set Access-Control-Allow-Methods "GET, HEAD, OPTIONS"
  63. Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
  64. Header set Access-Control-Allow-Credentials "true"
  65. # Fallback for development
  66. Header set Access-Control-Allow-Origin "*" env=!CORS_ALLOW_ORIGIN
  67. </Directory>
  68. ErrorLog ${APACHE_LOG_DIR}/error.log
  69. CustomLog ${APACHE_LOG_DIR}/access.log combined
  70. </VirtualHost>