Skip to content

Commit ad664b4

Browse files
committed
fix nginx config images
1 parent aa603c2 commit ad664b4

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

deployment/nginx/posdic-local.conf

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,21 @@ server {
5858
}
5959
}
6060

61-
# Product images
62-
location /product_images {
63-
alias /var/www/posdic/backend/product_images;
61+
# Product images - must come before static files regex
62+
location /product_images/ {
63+
alias /var/www/posdic/backend/product_images/;
6464
expires 7d;
6565
add_header Cache-Control "public";
66+
67+
# CORS headers for mobile app support
68+
add_header Access-Control-Allow-Origin $http_origin always;
69+
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
70+
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
71+
add_header Access-Control-Allow-Credentials "true" always;
6672
}
6773

68-
# Static files with cache
69-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
74+
# Static files with cache (excluding product_images to avoid conflict)
75+
location ~* ^/(?!product_images/).*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
7076
expires 30d;
7177
add_header Cache-Control "public";
7278
}
@@ -112,7 +118,7 @@ server {
112118
gzip_vary on;
113119
gzip_min_length 1024;
114120
gzip_comp_level 6;
115-
gzip_types text/plain text/css text/xml text/javascript
121+
gzip_types text/plain text/css text/xml text/javascript
116122
application/json application/javascript application/xml+rss;
117123

118124
# API Backend
@@ -126,29 +132,35 @@ server {
126132
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
127133
proxy_set_header X-Forwarded-Proto $scheme;
128134
proxy_cache_bypass $http_upgrade;
129-
135+
130136
# CORS headers for mobile app support (development)
131137
add_header Access-Control-Allow-Origin $http_origin always;
132138
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
133139
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
134140
add_header Access-Control-Allow-Credentials "true" always;
135141
add_header Access-Control-Max-Age 3600 always;
136-
142+
137143
# Handle preflight OPTIONS requests
138144
if ($request_method = 'OPTIONS') {
139145
return 204;
140146
}
141147
}
142148

143-
# Product images
144-
location /product_images {
145-
alias /var/www/posdic/backend/product_images;
149+
# Product images - must come before static files regex
150+
location /product_images/ {
151+
alias /var/www/posdic/backend/product_images/;
146152
expires 7d;
147153
add_header Cache-Control "public";
154+
155+
# CORS headers for mobile app support
156+
add_header Access-Control-Allow-Origin $http_origin always;
157+
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
158+
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
159+
add_header Access-Control-Allow-Credentials "true" always;
148160
}
149161

150-
# Static files with cache
151-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
162+
# Static files with cache (excluding product_images to avoid conflict)
163+
location ~* ^/(?!product_images/).*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
152164
expires 30d;
153165
add_header Cache-Control "public";
154166
}

deployment/nginx/posdic.conf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,21 @@ server {
9696
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
9797
}
9898

99-
# Product images
100-
location /product_images {
101-
alias /var/www/posdic/backend/product_images;
99+
# Product images - must come before static files regex
100+
location /product_images/ {
101+
alias /var/www/posdic/backend/product_images/;
102102
expires 7d;
103103
add_header Cache-Control "public, immutable";
104+
105+
# CORS headers for mobile app support
106+
add_header Access-Control-Allow-Origin $http_origin always;
107+
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
108+
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
109+
add_header Access-Control-Allow-Credentials "true" always;
104110
}
105111

106-
# Static files with cache
107-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
112+
# Static files with cache (excluding product_images to avoid conflict)
113+
location ~* ^/(?!product_images/).*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
108114
expires 1y;
109115
add_header Cache-Control "public, immutable";
110116
access_log off;

0 commit comments

Comments
 (0)