ThinkPHP6 project basic operation (2.Nginx configuration virtual domain name and simplified access path)

One, phpStudy creates a website

  1. Set access domain name
  2. Root directory fill in the project directory to the public directory
  3. Pay attention to check the synchronization hosts
  4. Confirm PHP version> 7.1.0
  5. Restart the Nginx server
  6. Can be accessed directly http://tp6.com/index.php/index/test
    (index/test is the test method written under the index controller)
    Insert picture description here

Two, hide index.php

If you want to hide index.php, direct access http://tp6.com/index/testyou need to configure Nginx server:

Method 1: vhosts.conf

Insert picture description here
Click the vhosts.confconfiguration file of the newly created website and add the code:

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

the complete document:

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;
        }
}

If you are not using an integrated environment, you can copy the above code to the Nginx related configuration file.

配置完成,重启Nginx服务器。

Now it can be accessed in two ways:
http://tp6.com/index/test
http://tp6.com/index.php/index/test

Insert picture description here

Insert picture description here

Method 2: phpStudy panel configuration pseudo-static

Site list> Management> Modify> Pseudo-static add the following code:
Insert picture description here

Method three: add the project root nginx.htaccessfile

Add code:

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

Guess you like

Origin blog.csdn.net/zy1281539626/article/details/110294256