diff --git a/Dockerfile b/Dockerfile index 3c91e38..62b3354 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM nginx:alpine3.20 COPY dist /usr/share/nginx/html # Copy custom Nginx configuration file to the container -COPY nginx.conf /etc/nginx/nginx.conf +COPY nginx-extra.conf /etc/nginx/conf.d/nginx-extra.conf # Expose the port that the application is running on EXPOSE 80 diff --git a/nginx-extra.conf b/nginx-extra.conf new file mode 100644 index 0000000..71230cc --- /dev/null +++ b/nginx-extra.conf @@ -0,0 +1,18 @@ +location / { + # other settings... + # Allow CORS for all domains (or specify a particular domain instead of *) + add_header 'Access-Control-Allow-Origin' '*'; + # Allow specific headers + add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; + # Allow specific methods + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } +} diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 4ee8485..0000000 --- a/nginx.conf +++ /dev/null @@ -1,38 +0,0 @@ -user www-data; - worker_processes auto; - pid /run/nginx.pid; - include /etc/nginx/modules-enabled/*.conf; - - events { - worker_connections 768; - } - - http { - server { - listen 80; - server_name yourdomain.com; - - location / { - # other settings... - # Allow CORS for all domains (or specify a particular domain instead of *) - add_header 'Access-Control-Allow-Origin' '*'; - # Allow specific headers - add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; - # Allow specific methods - add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; - add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain; charset=utf-8'; - add_header 'Content-Length' 0; - return 204; - } - } - } - - # Include other server and configuration files - include /etc/nginx/conf.d/*.conf; - include /etc/nginx/sites-enabled/*; - }