首页 热点资讯 义务教育 高等教育 出国留学 考研考公

nginx的alias虚拟目录如何支持php?

发布网友

我来回答

2个回答

热心网友

启用FastCGI,安装php-fpm~

热心网友

nginx 配置虚拟目录,并且支持PHP配置虚拟目录

server                                                                                                                  
{                                                                                                                       
        listen 80;                                                                                                      
        server_name www.5wx.org;                                                       
        index index.php index.html index.htm;                                                                           
        access_log /var/log/nginx/test.abc.com.log;                                                                

        autoindex on;                                                                                                   
        autoindex_exact_size off;                                                                                       
        autoindex_localtime on;                                                                                         

        location /transfer                                                                                              
        {                                                                                                               
                root /alidata/www/transfer;                                                                            
                if (!-e $request_filename){                                                                             
                    rewrite ^/index.php(.*)$ /index.php?s=$1 last;                                                      
                    rewrite ^(.*)$ /index.php?s=$1 last;                                                                
                    break;                                                                                              
                }                                                                                                       
        }                                                                                                               

        location /sms                                                                                                   
        {                                                                                                               
                root /alidata/www/sms;                                                                         
                if (!-e $request_filename){                                                                             
                    rewrite ^/index.php(.*)$ /index.php?s=$1 last;                                                      
                    rewrite ^(.*)$ /index.php?s=$1 last;                                                                
                    break;                                                                                              
                }                                                                                                       
        }                                                                                                               

        location /                                                                                                      
        {                                                                                                               
            root /alidata/www/ant_nest;                                                                                 

            #if (-f $request_filename) {                                                                                
            #       expires max;                                                                                        
            #       break;                                                                                              
            #}                                                                                                          


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

        location ~ .*\.(php|php5)?$                                                                                     
        {                                                                                                               
            if ( $request_uri ~ "^/transfer/" ){                                                                        
                    root /alidata/www/ant_nest2;                                                                        

            }                                                                                                           

            if ( $request_uri ~ "^/sms/" ){                                                                             
                    root /alidata/www/ant_nest_sms;                                                                     

            }                                                                                                           

            root /alidata/www/default;                                                                                 

            fastcgi_pass 127.0.0.1:9000;                                                                                
            fastcgi_index index.php;                                                                                    
            include fastcgi.conf;                                                                                       
            add_header request_uri $request_uri;                                                                        

            break;                                                                                                      
        } 

         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$                            
         {                                                                     
                  if (-f $request_filename) {                                  
                   expires -1s;                                                
                   break;                                                      
                   }                                                           
         }                                                                     

         location ~ /\.ht{                                                     
             deny all;                                                         
         }                                                                     

 }    

---------------------

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com