1. 程式人生 > >配置nginx使之支持pathinfo

配置nginx使之支持pathinfo

php nginx

phalcon項目,
oneinstack環境lnmp。
配置文件:
/usr/local/nginx/conf/vhost/dldh.ccc.conf
自動生成的。

問題:
除首頁外,其他都打不開,且樣式文件也打不開。
http://dldh.ccc/index.php/back/css/bootstrap.min.css
http://dldh.ccc/index.php/backend/index/index
都報: Access denied.

解決辦法:
作修改如下。


server {
  listen 80;
  server_name dldh.ccc;
  access_log off;
  index index.html index.htm index.php;
  root /web/dldh/public;

  try_files $uri $uri/ @rewrite; #增加這一句
                    location @rewrite{  #增加這一句
        rewrite ^/(.*)$ /index.php?_url=/$1; #增加這一句
  }

  #include /usr/local/nginx/conf/rewrite/none.conf;#註釋這一句
  #error_page 404 /404.html;
  #error_page 502 /502.html;

  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_split_path_info ^(.+\.php)(.*)$; #增加這一句
    fastcgi_param PATH_INFO $fastcgi_path_info; #增加這一句
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}

參考:
nginx下支持PATH_INFO詳解[1]
https://blog.csdn.net/hanzengyi/article/details/53483171
簡單配置nginx使之支持pathinfo
https://www.cnblogs.com/kzfbk/p/7302623.html

配置nginx使之支持pathinfo