BinaryONe commited on
Commit
2efa064
·
1 Parent(s): d58e22b

Nginx Changes-Over Alpine

Browse files
Files changed (2) hide show
  1. Dockerfile +12 -9
  2. nginx.conf +15 -17
Dockerfile CHANGED
@@ -5,33 +5,36 @@ RUN apk update && apk upgrade && \
5
  apk add --no-cache nginx python3 python3-dev py3-pip build-base libffi-dev openssl-dev shadow gcc musl-dev ca-certificates
6
 
7
  # Create a group and user
8
- RUN addgroup -S appgroup && adduser -S appuser -G appgroup
 
 
 
 
 
9
 
10
  # Set working directory
11
  WORKDIR /app
12
 
13
- # Copy requirements and install in ONE combined RUN command
14
  COPY requirements.txt /app/
15
  RUN python3 -m venv /app/venv && \
16
  /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
17
  /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \
18
- /app/venv/bin/pip list # Verify installation WITHIN THE SAME RUN COMMAND
19
 
20
  # Copy the rest of the application code
21
  COPY . /app
22
 
23
- # Copy Nginx config
24
  COPY nginx.conf /etc/nginx/conf.d/default.conf
25
 
26
- # Create necessary directories and set correct permissions
27
- RUN mkdir -p /var/www/html /var/log/nginx && \
28
- chown -R nginx:nginx /var/log/nginx && \
29
- chown -R appuser:appgroup /app /var/www/html
30
 
31
  # Switch to non-root user
32
  USER appuser
33
 
34
  EXPOSE 7860
35
 
36
- # Start Nginx and your application (using exec and the correct Python path)
37
  CMD ["sh", "-c", "exec /app/venv/bin/python -u -m FileStream & nginx -g 'daemon off;'"]
 
5
  apk add --no-cache nginx python3 python3-dev py3-pip build-base libffi-dev openssl-dev shadow gcc musl-dev ca-certificates
6
 
7
  # Create a group and user
8
+ RUN addgroup -S nginx && adduser -S -G nginx appuser
9
+
10
+ # Create necessary directories and set correct permissions (CRUCIAL FIX)
11
+ RUN mkdir -p /var/www/html /var/log/nginx /run/nginx && \
12
+ chown -R nginx:nginx /var/lib/nginx /var/log/nginx /run/nginx && \
13
+ chown -R appuser:nginx /app /var/www/html
14
 
15
  # Set working directory
16
  WORKDIR /app
17
 
18
+ # Copy requirements and install
19
  COPY requirements.txt /app/
20
  RUN python3 -m venv /app/venv && \
21
  /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
22
  /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \
23
+ /app/venv/bin/pip list
24
 
25
  # Copy the rest of the application code
26
  COPY . /app
27
 
28
+ # Copy Nginx config (default.conf - WITHOUT the http block)
29
  COPY nginx.conf /etc/nginx/conf.d/default.conf
30
 
31
+ # Remove the user directive from the main nginx.conf
32
+ RUN sed -i '/^user /d' /etc/nginx/nginx.conf
 
 
33
 
34
  # Switch to non-root user
35
  USER appuser
36
 
37
  EXPOSE 7860
38
 
39
+ # Start Nginx and your application
40
  CMD ["sh", "-c", "exec /app/venv/bin/python -u -m FileStream & nginx -g 'daemon off;'"]
nginx.conf CHANGED
@@ -1,22 +1,20 @@
1
- http { # The crucial http block
2
- server {
3
- listen 7860;
4
 
5
- proxy_buffering off;
6
- proxy_cache off;
7
- sendfile on;
8
- tcp_nopush on;
9
- tcp_nodelay on;
10
 
11
- location / {
12
- proxy_pass http://127.0.0.1:8080;
13
- proxy_set_header Host $host;
14
- proxy_set_header X-Real-IP $remote_addr;
15
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16
- proxy_set_header Range $http_range;
17
- proxy_set_header If-Range $http_if_range;
18
 
19
- add_header Accept-Ranges bytes;
20
- }
21
  }
22
  }
 
1
+ server {
2
+ listen 7860;
 
3
 
4
+ proxy_buffering off;
5
+ proxy_cache off;
6
+ sendfile on;
7
+ tcp_nopush on;
8
+ tcp_nodelay on;
9
 
10
+ location / {
11
+ proxy_pass http://127.0.0.1:8080;
12
+ proxy_set_header Host $host;
13
+ proxy_set_header X-Real-IP $remote_addr;
14
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15
+ proxy_set_header Range $http_range;
16
+ proxy_set_header If-Range $http_if_range;
17
 
18
+ add_header Accept-Ranges bytes;
 
19
  }
20
  }