Nginx服务服务器和静态构建

时间:2018-10-10 13:09:15

标签: nginx

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

  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面板的位置应该是这样,因为位置是根路径之后的路径。

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 /服务器模板的自定义页面)。

1 个答案:

答案 0 :(得分:0)

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

 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,则更改别名部分。