nginx配置thinkPHP5记录

  • A+
所属分类:PHP

nginx的版本为1.8.1,虚拟主机的配置文件为/etc/nginx/conf.d/rehack.cn.conf,配置文件内容如下:

server {
    listen 80;
    server_name form.cdbcck.com;
    root /var/www/rehack.cn/public/;
    index  index.html index.htm index.php;

    charset utf-8;
    location / {
	if (!-e $request_filename) {
	        rewrite  ^(.*)$  /index.php?s=/$1  last;
   		break;
    	}
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /var/www/rehack.cn/public$fastcgi_script_name;
	#fastcgi_param  PHP_VALUE  "open_basedir=/var/www/rehack.cn/:/tmp/:/proc/";
        include        fastcgi_params;
    }
}

配置好nginx需要重启下nginx  /bin/systemctl restart  nginx.service (centos7)

接下来在public目录下建立.htaccess文件,内容如下

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>

在根目录建立.htaccess文件,这样网站就安全了, 内容如下

RewriteEngine on
RewriteRule ^(.*)$ public/$1 [NC,L]

 

 

weinxin
我的微信公众号
我的微信公众号扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: