【问题标题】:Nginx serving server and static buildNginx 服务服务器和静态构建
【发布时间】:2018-10-10 13:09:15
【问题描述】:

我有一个在端口 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";
}

无论如何,我真的不知道如何正确配置。现在我无法获取我的构建文件,我尝试了这个配置的许多不同变体。 ATM 当我的所有路由location / 时,我有一个行为,即使我尝试对/admin 做出反应,它也会向我显示 404 页面(locations / 服务器模板的自定义页面)。

【问题讨论】:

    标签: nginx


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 2010-12-01
      • 2016-04-05
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      相关资源
      最近更新 更多