douzhe1264 2019-03-11 09:41
浏览 42

如何设置nginx反应pwa在一个文件夹和php apis在其他?

Disclaimer: I'm not a sys admin :)

I have the following setup: - react pwa in /var/www/react/build - php application under /var/www/html - site url mysite.loc I want all requests except mysite.loc/fapi/* and mysite.loc/api/* to be handled by react app and (fapi|api)/* by php app.

I am trying with the following nginx config:


    server {
        listen 80;
        listen [::]:80;

        server_name mysite.loc;

        root /var/www/react/build;
        index index.html index.php;

        location ^~ /fapi {
            rewrite ^/fapi/?(.*)$ /html/fapi/$1 last;
        }

        location ^~ /api {
            rewrite ^/api/?(.*)$ /html/api/$1 last;
        }

        location ^~ /html {
            index index.php;
            root /var/www;
            try_files $uri $uri/ /index.php$is_args$args;

            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_read_timeout 300;
            }
        }
    }

when accessing mysite.loc/fapi/user/get this config returns the following error: "/var/www/react/build/index.php" failed (2: No such file or directory)

what I was expecting was that the nginx would send request to /var/www/html/fapi/index.php. Not ideal but something I can work with.. Ideally I would like the request to go to /var/www/html/index.php, request being /fapi/user/get.

Can you point me into the right direction? Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制