VM12 Ubuntu16.04 配置Nginx支持ThinkPHP5.0框架,配置Pathinfo模式,血的教训!!!,搞了半天!!

跟着小滕的ThinkPHP入门,发现自己的ThinkPHP5.0和老师的不一样,搞了半天终于配好,坑爹啊

环境:

虚拟机环境:Ubuntu16.04

PHP版本:  PHP7.0

Web服务器: Nginx


我的Web服务器的根目录是/usr/share/nginx/html/

在Window下配置我的域名

①打开C盘

②进入C:\Windows\System32\drivers\etc目录

③用记事本打开hosts文件

④添加192.168.0.52 czq.fuckthephp.com到文件中


下面直接上配置文件,血的教训!!!

因为nginx.conf文件包含cond.d下的*.conf文件,所以只需在/etc/nginx/conf.d下创建thinkphp5.0支持的配置文件

在/etc/nginx/conf.d下新建test.conf文件

添加如下内容:

server {
        listen   80;
        server_name czq.fuckthephp.com;            #修改为自己配置的域名
        root /usr/share/nginx/html/tp5/public;    #修改为自己配置的Web根目录
        index index.php index.html index.htm;

        location / {
        }

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

        location ~ ^(.+\.php)(.*) {
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;      #修改为对于的php版本安装路径下的php7.0-fpm.sock文件
                fastcgi_index index.php;
                include fastcgi_params;        #    这里面fastcgi_params和 fcgi.conf内容是相同的,网上两种命名都有人用
                # include fcgi.conf;

                set $real_script_name $fastcgi_script_name;
                set $path_info "";
               if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){    # //if语句后面一定要有个空格,要和别的区分开,属于语法规定
                        set $real_script_name $1;
                        set $path_info $2;
                }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param   PATH_INFO $path_info;
        }
}

随便贴出我的nginx.conf配置文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

#location ^~ /module.cgi/ {
        #        fastcgi_pass 127.0.0.1:8082;
        #        fastcgi_index index.cgi;
        #        include fastcgi.conf;
        #}

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml         application/xml+rss text/javascript;

##
# Virtual Host Configs
##

#location ^~ /module.cgi/ {
        #        fastcgi_pass 127.0.0.1:8082;
        #        fastcgi_index index.cgi;
        #        include fastcgi.conf;
        #}

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";

# server {
# listen     localhost:110;
# protocol   pop3;
# proxy      on;
# }

# server {
# listen     localhost:143;
# protocol   imap;
# proxy      on;
# }
#}









































你可能感兴趣的:(web开发)