du94414 2014-12-03 09:55
浏览 225

在nginx配置下执行php脚本

I have the following nginx server block in its configuration

server {
    listen       80;
    server_name mydomain.com;
    location /deploy {
        alias /home/somedir/deploy/;
        }

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
  }

I want to execute a php file at the url mydomain.com/deploy/erp/index.php or mydomain.com/deploy/erp

The above thing downloads the php file instead of executing it. I googled and found solutions that asks you to define a www directory or something. I just need to execute the file in a specific directory at specific url. What are my options?

  • 写回答

1条回答 默认 最新

  • douye2572 2014-12-03 10:27
    关注

    You haven't told nginx what to do with .php files. Assuming you're using php-fpm, you'll need something like this:

    server {
      listen       80;
      server_name mydomain.com;
    
      root /home/somedir;
    
      location / {
        try_files $uri $uri/ =404;
      }
    
      location /deploy {
        try_files $uri $uri/ /index.php?$args;
      }
    
      location ~ \.php$ {
        try_files $uri =404;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题