proxy_pass优先级和位置

时间:2018-02-06 18:45:54

标签: nginx nginx-location

我正在尝试将所有来自nginx的传入请求代理到NodeJS,不包括uri“/ cabinet / ...”。所以根据官方的nginx文档,当我尝试在同一台服务器上继续执行文件时,它的工作非常完美,但是当我尝试代理到节点服务器时,整个请求被强制转换为节点(包括/ cabinet /)

那么我做错了什么?

server {
    listen 80;
    listen 443 ssl http2;
    server_name mysite.dev;
    root "/home/vagrant/code/cabinet/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        proxy_pass    http://localhost:5000;
        #try_files $uri $uri/ /index.html;
    }

    location /cabinet/ {
        #try_files $uri $uri/ /index.php?$query_string;
        try_files $uri $uri/ /index2.html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mysite.dev-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ /\.ht {
        deny all;
    }

    ssl_certificate     /etc/nginx/ssl/mysite.dev.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.dev.key;
}

0 个答案:

没有答案