0% found this document useful (0 votes)
4 views1 page

Secure NGINX Setup with Non-Root User

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Secure NGINX Setup with Non-Root User

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# Use the official NGINX image with a specific version for security and stability

FROM nginx:1.19-alpine

# Remove default configuration to avoid conflicts


RUN rm /etc/nginx/conf.d/[Link]

# Copy the custom NGINX configuration file


COPY [Link] /etc/nginx/[Link]

# Create a non-root user for running NGINX


RUN addgroup -S nginx && adduser -S nginx -G nginx

# Set permissions for NGINX user


RUN chown -R nginx:nginx /var/cache/nginx /var/run /var/log/nginx

# Switch to non-root user


USER nginx

# Expose the HTTP port


EXPOSE 80

# Use the non-root user to run NGINX for better security


CMD ["nginx", "-g", "daemon off;"]

You might also like