nginx thinkphp 配置文件

nginx下基于ThinkPHP框架的網(wǎng)站url重寫
可以參考以下兩個配置文件

server{        
     listen       80;
     server_name  localhost;
     #charset koi8-r;
     #access_log  logs/host.access.log  main;
     root /usr/local/lnmp/nginx1.10.3/html/thinkphp;
     index index.php;

     location / {
     if (!-e $request_filename) {
        rewrite  ^/(.*)$  /index.php/$1  last;
        break;
        }

     }
     location ~ \.php(/|$) {
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         include        fastcgi.conf;
         set $fastcgi_script_name2 $fastcgi_script_name;
         if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
            set $fastcgi_script_name2 $1;
            set $path_info $2;
          }
       fastcgi_param   PATH_INFO $path_info;
       fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
       fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
      }
 }

server {
    listen       80;
    server_name  thinkphp.lo;
    root /var/www;
    index  index.html index.htm index.php;

    error_page  404              /404.html;
    location = /404.html {
        return 404 'Sorry, File not Found!';
    }
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html; # windows用戶替換這個目錄
    }

    location / {
        try_files $uri @rewrite;
    }

    location @rewrite {
        set $static 0;
        if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
            set $static 1;
        }

        if ($static = 0) {
            rewrite ^/(.*)$ /index.php?s=/$1;
        }

    }

    location ~ /Uploads/.*\.php$ {
        deny all;
    }

    location ~ \.php/ {
       if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
       fastcgi_pass 127.0.0.1:9000;
       include fastcgi_params;
       fastcgi_param SCRIPT_NAME     $1;
       fastcgi_param PATH_INFO       $2;
       fastcgi_param SCRIPT_FILENAME $document_root$1;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,569評論 19 139
  • 第一章 Nginx簡介 Nginx是什么 沒有聽過Nginx?那么一定聽過它的“同行”Apache吧!Ngi...
    JokerW閱讀 33,022評論 24 1,002
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,275評論 6 342
  • 配置運行Nginx服務(wù)器用戶(組) 用于配置運行Nginx服務(wù)器用戶(組)的指令是user,其語法格式為: use...
    吃瓜的東閱讀 4,687評論 0 41
  • ?Burger Burger ?Depot ?The Grill by Sean Connolly ?Kiwi E...
    當當_7939閱讀 221評論 0 0

友情鏈接更多精彩內(nèi)容