日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

ThinkPHP6项目基操(2.Nginx配置虚拟域名及简化访问路径)

發布時間:2025/3/15 php 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ThinkPHP6项目基操(2.Nginx配置虚拟域名及简化访问路径) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Nginx配置虛擬域名及隱藏public和index.php路徑

    • 一、phpStudy 創建網站
    • 二、隱藏index.php
      • 方法一:vhosts.conf
      • 方法二:phpStudy面板配置偽靜態
      • 方法三:工程根目錄添加 `nginx.htaccess` 文件

一、phpStudy 創建網站

  • 設置訪問域名
  • 根目錄填寫項目目錄到public目錄
  • 注意勾選同步hosts
  • 確認PHP版本 > 7.1.0
  • 重啟Nginx服務器
  • 可以直接訪問 http://tp6.com/index.php/index/test
    (index/test是寫在index控制器下的test方法)
  • 二、隱藏index.php

    如果希望隱藏index.php,直接訪問 http://tp6.com/index/test需要再配置Nginx服務器:

    方法一:vhosts.conf


    點擊剛新建的網站的vhosts.conf配置文件,添加代碼:

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

    完整的文件:

    server {listen 80;server_name tp6.com;root "D:/phpstudy_pro/WWW/tp6/public";location / {index index.php index.html error/index.html;if (!-e $request_filename){ rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite ^/(.*)$ /index.php?s=$1 last; }error_page 400 /error/400.html;error_page 403 /error/403.html;error_page 404 /error/404.html;error_page 500 /error/500.html;error_page 501 /error/501.html;error_page 502 /error/502.html;error_page 503 /error/503.html;error_page 504 /error/504.html;error_page 505 /error/505.html;error_page 506 /error/506.html;error_page 507 /error/507.html;error_page 509 /error/509.html;error_page 510 /error/510.html;include D:/phpstudy_pro/WWW/tp6/public/nginx.htaccess;autoindex off;}location ~ \.php(.*)$ {fastcgi_pass 127.0.0.1:9004;fastcgi_index index.php;fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;include fastcgi_params;} }

    如果不是使用集成環境,可以將上面的代碼復制到Nginx相關配置文件中。

    配置完成,重啟Nginx服務器。

    現在下面兩種方式都可以訪問了:
    http://tp6.com/index/test
    http://tp6.com/index.php/index/test

    方法二:phpStudy面板配置偽靜態

    網站列表 > 管理 > 修改 > 偽靜態 添加以下代碼:

    方法三:工程根目錄添加 nginx.htaccess 文件

    添加代碼:

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

    ??重磅推薦:免費商用電商系統

    😏想白嫖整個電商系統用來商用?
    🤑想有自己的商城實現財富自由?
    🤓想學習最佳實踐提升自己技術?

    快來進入🚀 傳送門 🚀,開源免費、完整示例帶你快速入門,輕松二開,走上人生巔峰!👨?🎓

    總結

    以上是生活随笔為你收集整理的ThinkPHP6项目基操(2.Nginx配置虚拟域名及简化访问路径)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。