贝QAQ贝 2022-09-16 16:58 采纳率: 20.5%
浏览 52
已结题

docker使用nginx部署vue项目

vuex项目使用 打包

npm run build:prod

目录结构为:

img


nginx.conf配置为:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
                charset utf-8;

                location / {
            root  /usr/share/nginx/html/ruoyiadmin/dist;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
                
                location /prod-api/ {
                        proxy_set_header Host $http_host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header REMOTE-HOST $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_pass http://1.117.***.7:8080/;
                }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

default.conf配置为:


server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/ruoyiadmin/dist;
        index 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   /usr/share/nginx/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;
    #}
}

docker ps -a

CONTAINER ID   IMAGE           COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
9cfee0e78b33   nginx           "/docker-entrypoint.…"   15 minutes ago   Up 15 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp                      mynginx
5bfc44e79ab1   ruoyi:v1.0.0    "java -jar /ruoyi-ad…"   2 hours ago      Up 2 hours      0.0.0.0:8020->8020/tcp, :::8020->8020/tcp              jovial_lehmann
85de01dfc5ba   mysql:5.7       "docker-entrypoint.s…"   7 hours ago      Up 6 hours      0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
7a32f2a9df94   redis           "docker-entrypoint.s…"   24 hours ago     Up 7 hours      0.0.0.0:6379->6379/tcp, :::6379->6379/tcp              redis
cdfb89e21068   kdvolder/jdk8   "/bin/sh -c /bin/bash"   24 hours ago     Up 7 hours                                                             jdk1.8

浏览器访问报错

img

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 9月30日
      • 已采纳回答 9月22日
      • 创建了问题 9月16日

      悬赏问题

      • ¥15 ubuntu18.04 tty报错&tty界面su/sudo命令无法执行,如何解决?
      • ¥20 关于c语言网络编程,实现传文件和即时聊天
      • ¥20 下面的压缩方法是否可行
      • ¥15 结构体数组读取文件信息失败,读取不了
      • ¥15 kaldi thchs30 训练遇到问题
      • ¥15 shellter无法使用,如何解决?(操作系统-kali)
      • ¥15 matlab动态模态分解程序
      • ¥60 关于渗透及远控的几个问题
      • ¥15 python文本词汇出现次数统计
      • ¥15 使用按键和串口,记录按键在不消抖的情况下触发的次数