Nginx服务服务器和静态构建 [英] Nginx serving server and static build

查看:77
本文介绍了Nginx服务服务器和静态构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在端口3000上运行的next.js服务器,并且我具有静态构建(使用create-react-app创建),应该是管理面板.看起来像这样

I have one next.js server that is running on port 3000 and I have static build (created with create-react-app), that should be admin panel. So it looks like this

  server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/city-am-club/admin/build/;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

 location /admin/ {
        root /usr/share/nginx/myproject/admin/build;
        index index.html index.htm;
        try_files $uri /index.html;
        default_type "text/html";
    }
location / {        
        rewrite /(.*) /$1  break;
        proxy_pass http://127.0.0.1:3000;
}

}

我知道admni面板的位置应该是这样,因为位置是根路径之后的路径.

I understand that location should be like this with admni panel, cause location is path after root path.

location / {        
        root /usr/share/nginx/myproject/admin/build;
        index index.html index.htm;
        try_files $uri /index.html;
        default_type "text/html";
}

无论如何,我真的不知道如何正确配置此设置.现在,我无法获得内置文件,我尝试了此配置的许多不同变体.当我的所有路由为location /时,即使在尝试响应/admin时,ATM也会显示404页面(locations /服务器模板的自定义页面).

Any way, I don't really know how to configure this correct. Right now I cannot get my built files, i tried a lot of different variations of this config. ATM I have a behavior when all my routes location /, even when I try to react /admin it shows me 404 page (custom page of locations / server template).

推荐答案

为您的NGINX配置尝试此操作.

Try this for your NGINX config.

 server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/city-am-club/admin/build/;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

location / {        
        rewrite /(.*) /$1  break;
        proxy_pass http://127.0.0.1:3000;

        location /admin/ {
        alias /usr/share/nginx/myproject/admin/build;
        index index.html index.htm;
        try_files $uri /index.html;
        default_type "text/html";
        }

}

如果管理路径不是/usr/share/nginx/myproject/admin/build,则更改别名部分.

If the admin path is not /usr/share/nginx/myproject/admin/build then change the alias section.

这篇关于Nginx服务服务器和静态构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆