ry的vue项目配置外部链接跳转,在nginx中无法正常显示页面,如何解决?

ry的vue项目配置外部链接跳转,在nginx中无法正常显示页面,在自己的代码是没有问题的,大家帮忙看看问题,谢谢

img

img

问题已解决,vue框架拦截的

在你对AIndex和BIndex的配置中,把端口号带上, http:// localhost: 8091/AIndex 试试

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/1104550
  • 这篇博客也不错, 你可以看下多个vue项目如何用nginx部署在同一端口下
  • 除此之外, 这篇博客: 绝对路径打包前端资源在Nginx中代理配置中的 问题1,如何正确将打包后的vue项目在nginx中部署 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  •         vue前端项目打包之后,静态资源就只有也给index.html文件一些js/css资源文件,部署的时候,可以直接将打包好的静态资源放到Nginx的html目录下去访问,但是如果我们将资源放到html/demo目录下,然后配置过滤路径之后去访问,会发现和在开发环境中访问的效果不同。 在开发环境中,可以直接输入路由地址,但是部署到nginx之后,必须是http:/ip:port/demo/index.html才行,然后后面再去跟路由的时候,发现页面不能按照预期的方式渲染和输出,总是找不到对应的页面。 这主要是Nginx里的配置不正确导致的。 

            如下给一个可用的配置

    server {
            listen       8013;
            limit_conn perip 10;
            limit_rate 1024k;
            #charset koi8-r;
    
            access_log  logs/access_8013.log  main;
    		
    		
    		location  /portal {
                root   html/smartdata;
                index  index.html index.htm;
                try_files $uri $uri/ /portal/$args;   
                if ($request_filename ~* .*\.(?:js|css|svg|png|jpg)$)
                  {
                       expires      7d;
                 }
    		}
    }

            静态资源的路劲是  html/smartdata/portal,如下所示:

            按照这种方式配置,实际上就是匹配url中的portal,然后到html/smartdata目录下去找portal这个文件,显然是没有这个文件,然后到portal目录下去找对应index.html。这块关于index的 指令可以参考这篇博文,写的还是很好的。

  • 您还可以看一下 杨千锋老师的分布式之nginx环境搭建视频课程中的 集群需求小节, 巩固相关知识点

这个是之前配置的,可以参考下看看


#user  nobody;
worker_processes  1;

#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;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:\git\ry-Vue3\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://localhost:8080/;
        }

        #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;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}