专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

Docker+Nginx部署vue项目

环境

  • Centos 7
  • Docker
  • Nginx

将项目打包

yarn run build

打包生成生成dist静态资源目录

82_1.png

我这里资源文件放置在阿里云服务器/usr/gaolei/dockers/nginx-docker

82_2.png

82_3.png

编写Dockerfile

vim Dockefile

82_4.png

# Base Image设置基础镜像
FROM nginx

#Define Author 定义作者
# maintainer [已遗弃]
# MAINTAINER DuebassLei 1130122701@qq.com
LABEL maintaniner="DuebassLei"

# 将文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面
COPY vueAdmin/  /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf

编辑nginx.conf

worker_processes auto;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    client_max_body_size   20m;
    server {
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
     location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

构建自定义镜像

# 默认使用当前目录下的Dockerfile构建
docker build -t nginx:v1 .

82_5.png

查看镜像

docker images

82_6.png

启动并查看运行容器

# -p 端口转发 宿主机端口:容器端口  
docker run -p 9999:80 -d nginx:v1
docker ps

82_7.png

访问效果

82_8.png

文章永久链接:https://tech.souyunku.com/44122

未经允许不得转载:搜云库技术团队 » Docker+Nginx部署vue项目

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们