Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx非根目录部署无法正常访问 #4085

Open
zxingkong opened this issue Apr 25, 2019 · 7 comments

Comments

Projects
None yet
4 participants
@zxingkong
Copy link

commented Apr 25, 2019

匹配不到nginx配置的目录,会匹配到根目录的web项目中�去。
看了所以相关的issue,仍然没解决。前端新手,跪求指教。。。
相关配置:
config.js
image
nginx配置
image
项目实际部署路径
image

@chenshuai2144

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2019

https://umijs.org/zh/config/#base
试试这个。应该搞个文档了

@zxingkong

This comment has been minimized.

Copy link
Author

commented Apr 26, 2019

https://umijs.org/zh/config/#base
试试这个。应该搞个文档了

您好,这个base 跟publicPath已经配置了。能帮我看下,是哪个地址配置错了吗,我现在访问http://visitortest.skyingidea.com/serverfortemp/visitor_web会跳转到根目录的antd mobile项目去

@Tzng

This comment has been minimized.

Copy link

commented Apr 26, 2019

我用express可以部署非根目录。这么配置的

  manifest: {
    basePath: '/demo',
  },
 // 静态资源地址的配置可以让一个端口下,放好几个项目
  publicPath: '/test/demo/',
  chainWebpack: webpackPlugin,

然后express这么写的

app.use('/', express.static(__dirname + '/'));

server.js的同级目录有一个demo文件夹,然后这个文件夹里面放打包好的代码

然后我的nginx直接配置转发到server.js启动的端口

		location /demo/ {
			proxy_pass http://127.0.0.1:3001/;
		}
@sunguoxing0628

This comment has been minimized.

Copy link

commented Apr 27, 2019

@zxingkong 我这里直接是用的80端口,没有系统名称,访问地址为http://{ip}/{router}结构。我使用的是nginx,如果是使用ant-design-pro这个项目直接生成的话,不需要配置basepublicPath

        #添加拦截路径和根目录
        location / {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

其中html/reporting是指nginx的根目录的,在html目录创建了reporting目录,reporting里就是拷贝的dist文件夹内容。

我觉得你可以尝试两个操作:

  1. 去掉basepublicPath
  2. 同时注意一下location后面的路径,要用/结尾。
        #添加拦截路径和根目录
        location /reporting/ {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }
@zxingkong

This comment has been minimized.

Copy link
Author

commented Apr 29, 2019

@zxingkong 我这里直接是用的80端口,没有系统名称,访问地址为http://{ip}/{router}结构。我使用的是nginx,如果是使用ant-design-pro这个项目直接生成的话,不需要配置basepublicPath

        #添加拦截路径和根目录
        location / {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

其中html/reporting是指nginx的根目录的,在html目录创建了reporting目录,reporting里就是拷贝的dist文件夹内容。

我觉得你可以尝试两个操作:

  1. 去掉basepublicPath
  2. 同时注意一下location后面的路径,要用/结尾。
        #添加拦截路径和根目录
        location /reporting/ {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

额,按照您说的,我修改了下配置,发现这样访问是会404

@sunguoxing0628

This comment has been minimized.

Copy link

commented Apr 29, 2019

@zxingkong 我这里直接是用的80端口,没有系统名称,访问地址为http://{ip}/{router}结构。我使用的是nginx,如果是使用ant-design-pro这个项目直接生成的话,不需要配置basepublicPath

        #添加拦截路径和根目录
        location / {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

其中html/reporting是指nginx的根目录的,在html目录创建了reporting目录,reporting里就是拷贝的dist文件夹内容。
我觉得你可以尝试两个操作:

  1. 去掉basepublicPath
  2. 同时注意一下location后面的路径,要用/结尾。
        #添加拦截路径和根目录
        location /reporting/ {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

额,按照您说的,我修改了下配置,发现这样访问是会404

你是否注意到root后不是/开头

@zxingkong

This comment has been minimized.

Copy link
Author

commented May 4, 2019

@zxingkong 我这里直接是用的80端口,没有系统名称,访问地址为http://{ip}/{router}结构。我使用的是nginx,如果是使用ant-design-pro这个项目直接生成的话,不需要配置basepublicPath

        #添加拦截路径和根目录
        location / {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

其中html/reporting是指nginx的根目录的,在html目录创建了reporting目录,reporting里就是拷贝的dist文件夹内容。
我觉得你可以尝试两个操作:

  1. 去掉basepublicPath
  2. 同时注意一下location后面的路径,要用/结尾。
        #添加拦截路径和根目录
        location /reporting/ {
            root   html/reporting;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

额,按照您说的,我修改了下配置,发现这样访问是会404

你是否注意到root后不是/开头

这样配置:
location /visitor_web/ { root visitor_web; index index.htm index.html; try_files $uri $uri/ /index.html; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.