nginx配置为以domain.com的形式运行节点,并以domain.com/phptest的形式在子文件夹中运行php
我可以在端口8080上运行节点,并将其指向domain.com,但我想在它旁边运行php 示例配置如下所示:nginx配置为以domain.com的形式运行节点,并以domain.com/phptest的形式在子文件夹中运行php,php,node.js,nginx,Php,Node.js,Nginx,我可以在端口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.
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解析器)
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;
}
}
}