阿里云下nginx+php+mysql+codeigniter的配置

最近开发的站点使用的阿里云的弹性计算A套餐。

使用官方的论坛的一键安装包安装了nginx+php+mysql。要注意的是脚本会提示选择服务器脚本,但是不会选择php版本,默认是5.2.7。由于用到了5.3以上的新特性,比如json_encode支持中文(5.3以下不支持),所以想更改,看了以下install.sh,直接把里面的一个叫php变量的由2改成3就行了,安装包里是已经有5.3的包的。

安装好以后将codeigniter 2.2的框架移植过去以后出现了502错误。找了很久,最后在stackflow上看到要确认一下php-fpm的进程是否在。用' ps as | grep php'看,果然没有。于是到php安装文件下找到php-fpm执行一下就行了。

然后碰到的是codeigniter开启clean url后需要rewrite支持的问题,2个地方要注意,一是conf文件,下面贴出我的,具体就不赘述了。

 1 server {
2 listen 80;
3 server_name localhost;
4 index index.html index.htm index.php;
5 root /PATH_TO_YOU_ROOT_FOLDER;
6
7 location / {
8
9 index index.php index.html index.htm;
10 if ( $request_filename !~ (uploads|js|css|views|robots/.txt|index/.php.*) ) {
11 rewrite ^/(.*)$ /index.php/$1 last;
12 break;
13 }
14
15 }
16
17 location ~ /index.php/
18 {
19 #fastcgi_pass unix:/tmp/php-cgi.sock;
20 fastcgi_pass 127.0.0.1:9000;
21 fastcgi_index index.php;
22 include fastcgi.conf;
23
24 fastcgi_param SCRIPT_FILENAME /PATH_TO_YOU_ROOT_FOLDER/index.php;
25 fastcgi_param PATH_INFO $fastcgi_script_name;
26 }
27
28
29 log_format mumoon '$remote_addr - $remote_user [$time_local] "$request" '
30 '$status $body_bytes_sent "$http_referer" '
31 '"$http_user_agent" "$http_x_forwarded_for"';
32 access_log /alidata/log/nginx/access/mumoon.log mumoon;
33 error_log /alidata/log/nginx/error/mumoon.log debug;
34 }

里面有几个地方改成需要的参数就行了。

二是CI的config文件需要修改,将index_page一项变成空的,不要写index.php,写了的话会导致系统不断重定向。

顺便一提,阿里云还是挺好用,感觉速度够快,可以很方便的启动停止。在控制台还有个重置功能,相当于重装服务器。

睡觉去了~

原文地址:https://www.cnblogs.com/sskyy/p/2378937.html