Skip to content

Commit 44b1e0f

Browse files
add: nginx config
1 parent bca3369 commit 44b1e0f

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ ENTRYPOINT ["nginx", "-g", "daemon off;"]
5353
# docker run -d \
5454
# --name realworld-react \
5555
# --restart unless-stopped \
56-
# -p 3000:80 \
56+
# -p 127.0.0.1:3000:80 \
5757
# minhhoccode111/realworld-react:latest

nginx/nginx-host.conf

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ server {
4949
return 301 https://$server_name$request_uri;
5050
}
5151

52-
# Frontend static serving
52+
# Frontend reverse proxy to Docker container
5353
server {
5454
listen 443 ssl;
5555
http2 on;
@@ -59,23 +59,25 @@ server {
5959
ssl_certificate /etc/letsencrypt/live/realworld.minhhoccode111.com/fullchain.pem;
6060
ssl_certificate_key /etc/letsencrypt/live/realworld.minhhoccode111.com/privkey.pem;
6161

62-
# Path to your React 'dist' or 'build' folder
63-
root /var/www/realworld-react/dist;
64-
index index.html;
65-
66-
# React Router Fix: Fallback to index.html for SPA routing
62+
# Reverse proxy to nginx-alpine container on port 3000
6763
location / {
68-
try_files $uri $uri/ /index.html;
69-
}
64+
proxy_pass http://127.0.0.1:3000;
65+
proxy_http_version 1.1;
7066

71-
# Static Assets Caching
72-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
73-
# limit_req zone=static_limit burst=20 nodelay;
67+
# Standard proxy headers
68+
proxy_set_header Host $host;
69+
proxy_set_header X-Real-IP $remote_addr;
70+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71+
proxy_set_header X-Forwarded-Proto $scheme;
7472

75-
etag on;
76-
expires 1y;
77-
add_header Cache-Control "public, immutable";
78-
access_log off;
73+
# WebSocket support (if needed for development)
74+
proxy_set_header Upgrade $http_upgrade;
75+
proxy_set_header Connection "upgrade";
76+
77+
# Timeouts
78+
proxy_connect_timeout 60s;
79+
proxy_send_timeout 60s;
80+
proxy_read_timeout 60s;
7981
}
8082

8183
# Security Headers

nginx/nginx.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
server {
22
listen 80;
33

4+
# Gzip compression
5+
gzip on;
6+
gzip_vary on;
7+
gzip_min_length 1024;
8+
gzip_comp_level 6;
9+
gzip_types
10+
text/plain
11+
text/css
12+
text/xml
13+
text/javascript
14+
application/json
15+
application/javascript
16+
application/xml+rss
17+
application/rss+xml
18+
font/truetype
19+
font/opentype
20+
application/vnd.ms-fontobject
21+
image/svg+xml;
22+
gzip_disable "msie6";
23+
24+
# React Router Fix: Fallback to index.html for SPA routing
425
location / {
526
root /usr/share/nginx/html;
627
index index.html index.htm;
728
try_files $uri /index.html =404;
829
}
930

31+
# Static Assets Caching
32+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp|avif)$ {
33+
root /usr/share/nginx/html;
34+
etag on;
35+
expires 1y;
36+
add_header Cache-Control "public, immutable";
37+
access_log off;
38+
}
39+
1040
error_page 500 502 503 504 /50x.html;
1141

1242
location = /50x.html {

0 commit comments

Comments
 (0)