【问题标题】:nginx configuration to run node as domain.com and php in subfolder as domain.com/phptestnginx 配置将节点作为 domain.com 运行,并将子文件夹中的 php 作为 domain.com/phptest
【发布时间】:2017-01-01 02:27:37
【问题描述】:

我可以在端口 8080 上运行节点并将其指向 domain.com,但我想在它旁边运行 php。

示例配置如下:

proxy_buffering on;
proxy_buffer_size 1k;
proxy_buffers 24 4k;
proxy_busy_buffers_size 8k;
proxy_max_temp_file_size 2048m;
proxy_temp_file_write_size 32k;

server {
listen 80;
server_name domain.com;
location / {

         proxy_pass  http://domain.com:8080;
         proxy_redirect off;
         proxy_set_header        X-Forwarded-For $remote_addr;

         location ~* \.(html|css|jpg|gif|ico|js)$ {
                proxy_cache          cache;
                proxy_cache_key      $host$uri$is_args$args;
                proxy_cache_valid    200 301 302 30m;
                expires              30m;
                proxy_pass  http://domain.com:8080;
         }
    }
}

现在我想将 domain.com/php 作为 php 服务器运行,因此任何具有 domain.com/php 的请求都将处理 php,而其他请求将在节点上运行。有可能吗?

【问题讨论】:

  • 是的..您只需创建一个新位置并将其转发到 FPM(适用于 nginx 的 php 解析器)

标签: php node.js nginx


【解决方案1】:
 server {
 listen 80;
 server_name www.domain.com;
 root /var/www/html/testphp/api;
 location / {
 proxy_pass  http://www.domain.com:8080;
 proxy_redirect off;
 proxy_set_header        X-Forwarded-For $remote_addr;
 location ~* \.(html|css|jpg|gif|ico|js)$ {
    proxy_cache          cache;
    proxy_cache_key      $host$uri$is_args$args;
    proxy_cache_valid    200 301 302 30m;
    expires              30m;
    proxy_pass  http://www.domain.com:8080;
    }
}

location  /api/ {
    alias /var/www/html/testphp/api/;
    try_files $uri $uri/ /api/index.php;
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_pass unix:/run/php/php5.6-fpm.sock;
        fastcgi_param   SCRIPT_FILENAME $request_filename;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2014-11-14
    • 2017-11-29
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    相关资源
    最近更新 更多