nginx 与 php 和两个 node.js 路由

nginx 与 php 和两个 node.js 路由

我有两条路由想要传递两个节点进程(websocket 路由、angular 应用程序),而第三条路由需要传递给一个 php 应用程序,该应用程序充当 angular 应用程序的 rest api。我对 nginx 不是很精通

以下是我尝试过的:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


    include /etc/nginx/conf.d/*.conf;

    fastcgi_hide_header Server;
    fastcgi_hide_header X-Powered-By;

    #upstream servers

    upstream app_servers {
        ip_hash;
        server dev.example.com:9001 weight=5;
    }
    upstream socket_servers {
        ip_hash;
        server  dev.example.com:9002 weight=5;
    }
    #upstream api_servers {
        #ip_hash;
        # server  dev.example.com:9000;
    #}
    server {
        listen 80;
        server_name dev.example.com;
        root /usr/share/nginx/html/dev/;
        server_tokens off;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";    



        # cache statics
        location ~* .(png|gif|jpg|jpeg|ico|css|js)$ {
            expires max;
            access_log off;
        }


        # php config
        location ~ \.(hh|php)$ {
            try_files $uri = 404;
            location ~ \..*/.*\.php$ {return 404;}
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_keep_conn on;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        #rest api
        location /api {
            include /etc/nginx/mime.types;
            index index.php;
            try_files $uri /api/index.php?$request_uri;
        }
        #websocket server
        location /sock {
            proxy_pass http://socket_servers;
        }
        #angular app
        location / {
            proxy_pass http://app_servers;
        }

    }

}

所有请求似乎都最终出现在 Angular 应用程序中,即使在请求时也是/sock如此/api。有什么想法吗?

相关内容