Home > PHP Framework > ThinkPHP > Record how Nginx configures TP5.1 and the problems encountered

Record how Nginx configures TP5.1 and the problems encountered

藏色散人
Release: 2022-01-05 16:28:40
forward
2613 people have browsed it

下面thinkphp框架教程栏目将给大家介绍关于Nginx怎么配置ThinkPHP5.1以及遇到的问题的解决方法,希望对需要的朋友有所帮助!

1.Nginx用户对项目目录的访问权限

cd /usr/local/nginx/html/setfacl -m u:nginx:rwx -R ../html
Copy after login

2.确保访问路径是正确的,最好在本地测过访问URL路径能正确访问到文件

Record how Nginx configures TP5.1 and the problems encountered

3.nginx支持tp的pathinfo

vi /usr/local/nginx/conf/nginx.conf
Copy after login
Copy after login

nginx.conf配置文件找到位置修改内容为

 location ~ \.php$ {
            #root           html;
            #这段路径指向是必须加的
           root       /usr/local/nginx/html/zh/public;
           fastcgi_index index.php;
           fastcgi_pass   127.0.0.1:9000;
           #fastcgi_pass   unix:/usr/local/php/var/run/www.sock;
           fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(.*)$;     #增加这一句
            fastcgi_param PATH_INFO $fastcgi_path_info;    #增加这一句
           include        fastcgi_params;
        }
Copy after login

4.nginx rewrite重写规则

vi /usr/local/nginx/conf/nginx.conf
Copy after login
Copy after login

nginx.conf配置文件找到位置修改内容为

server {
        listen       80;
        server_name  www.liuyuanshan.top;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            # 设置www.liuyuanshan.top默认访问路径为/usr/local/nginx/html/zh/public/
             root    /usr/local/nginx/html/zh/public/;
            index index.php  index.html index.htm;

                if (!-e $request_filename) {
                        rewrite  ^(.*)$  /index.php?s=/$1  last;
                }
        }
Copy after login

推荐学习:《最新的10个thinkphp视频教程

The above is the detailed content of Record how Nginx configures TP5.1 and the problems encountered. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template