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 @   柴高八斗  阅读(478)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示