Docker-Nginx镜像常用配置

91 阅读1分钟

使用Docker发布前端项目,基于Nginx作为服务器发布时,常用的Nginx配置。

Dockerfile

FROM nginx
COPY ./  /usr/share/nginx/html/
COPY ./nginx.conf /etc/nginx/nginx.conf

nginx.conf

user root;
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    
    server {
        listen       80;
        server_name  localhost;
 
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            error_page 405 =200 http://$host$request_uri;
            try_files $uri $uri/ /index.html;
            gzip  on;
            gzip_comp_level 6;
            gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php;
        }
    }
}