douwen5833 2014-02-01 10:34
浏览 38

Nginx + php5-fpm + node.js

Solved

I had a problem in my nginx conf file.

Code location ~* \.(?:ico|css|js|gif|jpe?g|png)$ is most specific match, so I had change the line:

location /node/

to:

location ^~ /node/

and now all is ok.

Question

Firstly, apologize for my English.

I have problem with nginx and node.js, I want to serve all files with nginx, .php files with php5-fpm and files from domain.com/node/ with node.js And my configuration do it, but I have problem with scripts in HTML documents e.g.

<script type="text/javascript" src="http://domain.com/node/socket.io/socket.io.js"></script>

show me error 404, and node.js not serve this file.

This is my configuration:

server {
    server_name www.domain.com;
    listen 80;

    return 301 http://domain.com$request_uri;
}

server {
    server_name domain.com;
    listen 80;

    access_log /var/log/nginx/domain_com_access_log;
    error_log  /var/log/nginx/domain_com_error_log;
    root       /home/domain_com/www;

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$
    {
        expires max;
        access_log off;
        log_not_found off;
    }

    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.          { access_log off; log_not_found off; deny all; }
    location ~ ~$           { access_log off; log_not_found off; deny all; }

    location ~ cache/(.*)$
    {
        deny all;
    }

    location /node/
    {
        try_files $uri = 404;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:1234/;
        proxy_redirect off;
    }

    location ~ \.php$
    {
        try_files $uri = 404;
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fpm_domain_com.sock;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试