Nginx PHP index.php 重写不允许代理传递到“/writing”

Nginx PHP index.php 重写不允许代理传递到“/writing”

我想要的:我希望显示 laravel 站点,除非它是用于/writing。在这种情况下,我希望它将该子目录中的所有内容代理传递到 nodejs 站点。

会发生什么:laravel 站点捕获请求并表示找不到请求的路由,而不是允许 Node 站点显示在那里。通过此配置,Node 站点根本不会显示

我正在尝试获取一个网站(php,特别是 laravel),它使用重写来工作,同时在子目录中使用另一个网站(nodejs)/writing

我一直在重定向循环和 laravel 之间徘徊,以捕获请求,但我发现的任何内容似乎都与我所做的事情无关,并且如果这是问题所在,也没有给我关于如何正确修复我的结构的建议。

server {
    listen  80; ## listen for ipv4; this line is default and implied
    server_name .domain.tld;

    root /var/www/vhosts/domain/public;
    index index.php index.html index.htm;

    location /writing/ {
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_pass         http://127.0.0.1:xxxx;
            proxy_redirect off;
        }   

    location / {
        try_files $uri $uri/ /index.html;
    }

    # Removes trailing slashes
    if (!-d $request_filename) {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # Rewrite to index.php unless the request is for an existing file (image, js, css, etc.)
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

    location ~ /\.ht {
        deny all;
    }

}

相关内容