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

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 linux平台中qt触屏偶尔不响应
      • ¥15 不使用zk实现双机clickhouse、kafka数据同步
      • ¥15 使用Labwindows/CVI程控万用表时自动切换量程
      • ¥15 Matlab修改xml参数后允许不了exe文件
      • ¥15 用flask框架接收前端上传的文本文件后怎么读取该文件
      • ¥15 有没有嵌入式ubuntu的朋友
      • ¥50 diddler Burp Suite
      • ¥20 关于UE5.1的问题,求专家解答!
      • ¥30 关于#爬虫#的问题:百度为您找到相关结果约100,000,000个 但只展现70页 有没有可能提取出来全部的搜索结果
      • ¥40 IIS部署API,弄了几天没弄出来,希望带佬远程帮我弄一下,有偿