Linxu下Yii2的POST请求被拒经历

Linxu下Yii2的POST提交被拒经历

 

介于对Yii2的使用,浅谈一下自己的经验,在以往的项目中我使用的框架是Yii1,由于Yii2的出现,所以极力的想使用一下它的新特性。

 

我的使用环境Linux系统是CentOS 7.3,Nginx1.12.0安装的PHP版本为PHP 7.0.12:

 

Apache服务器端站点配置

1、修改配置文件:/etc/httpd/conf/httpd.conf中修改两处,若配置虚拟域名另参照其它配置。

DocumentRoot "/data1/vhosts/webapp/app.xxx.com"

 

<Directory "/data1/vhosts/webapp/app. xxx.com">

 

2、重定向站点目录,当前目录为 /data1/vhosts/webapp/app. xxx.com,该目录下有文件.htaccess

 

隐藏文件.htaccess中配置内容:

# prevent directory listings

Options -Indexes

# follow symbolic links

Options FollowSymlinks

RewriteEngine on

   

RewriteCond %{REQUEST_URI} ^.*$

RewriteRule ^(.*)$ /api/web/$1

 

Nginx服务器端站点配置

修改配置文件:/web/soft/nginx/conf/conf.d/default.conf

 

server {

    listen       80;

    server_name  10.0.194.80;

    root   /web/www/www.xxx.com/api/web;

 

    location / {

        index  index.php index.html index.htm;

        try_files $uri $uri/ /index.php?$args;

    }

 

    location ~ /\.(ht|svn|git) {

        deny all;

    }

 

    location = /50x.html {

        root   html;

    }

 

    location ~* apple-touch-icon {

        access_log off;

        rewrite .* /fav-icon.png last;

    }

 

 

    location ~ \.php$ {

        try_files $uri = 404;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }

    error_page  404              /404.html;

    error_page   500 502 503 504  /50x.html;

 

    access_log  /web/log/nginx/default.access.log;

}

 

 

特别说明:

Apache站点目录下的.htaccess文件中的内容移植到Nginx下需要在default.conf中配置,内容即为:

try_files $uri $uri/ /index.php?$args;

 

 

遇到问题

按照上面的配置,Yii2框架的站点可以正常访问,做到这认为一切OK。但是在此时遇到了一个很棘手的问题:手机app端以POST方式请求API的Web接口返回500错误,而PC端浏览器POST请求没问题。在此为Yii2的新手排解一些问题:

posted @ 2019-09-27 16:33  柴高八斗  阅读(467)  评论(0编辑  收藏  举报