thinkphp5配置nginx訪問
阿新 • • 發佈:2019-02-02
thinkphp採用pathinfo模式;不像laravel和yii配置上去直接就可以幹;
測試了兩個不同方式的nginx安裝 yum 和lnmp一鍵安裝包;
一鍵安裝包裡面有對pathinfo的支援
下面是配置
一鍵安裝包安裝的lnmp centos7
server { listen 8080 default_server; #listen [::]:80 default_server ipv6only=on; server_name _; index index.html index.htm index.php; root /var/www/html/ibjson; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php.conf; location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$1 last; } } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/access.log; }
nginx埠轉發的配置如下
server{ listen 8089; server_name _; root /var/www/html/tp5/public; index index.php index.html index.htm; location ~ \.php/?.* { root /var/www/html/tp5/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #定義變數 $path_info ,用於存放pathinfo資訊 set $path_info ""; #定義變數 $real_script_name,用於存放真實地址 set $real_script_name $fastcgi_script_name; #如果地址與引號內的正則表示式匹配 if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { #將檔案地址賦值給變數 $real_script_name set $real_script_name $1; #將檔案地址後的引數賦值給變數 $path_info set $path_info $2; } #配置fastcgi的一些引數 fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } location / { try_files $uri $uri/ /index.php?$query_string; } }