鍍金池/ 問答/PHP  Linux/ nginx phpstudy 怎么配置隱藏index.php?

nginx phpstudy 怎么配置隱藏index.php?

windows系統(tǒng) phpstudy集成環(huán)境,nginx服務(wù), 安裝laravel后除了首頁可以訪問,make:auth后的注冊和登錄頁面都不能訪問,網(wǎng)上查找原因發(fā)現(xiàn)只要在域名后面把index.php寫上就行,然后知道是pathinfo 的問題,在nginx的vhosts.conf文件上按照文檔的指導(dǎo)加了一行

try_files $uri $uri/ /index.php?$query_string;

這個是我的vhost.conf配置文件內(nèi)容,除了上面一行,其它都沒動:

server {
        listen       80;
        server_name  laravel.demo.com ;
        root   "E:/pms/laravel/public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            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;
        }
}

現(xiàn)在倒是地址自動添加index.php了,但是按照文檔所說,加上try_files那一行是為了美化url, 但是反而是自動添加index.php了,怎么隱藏這個index.php?我網(wǎng)上查的,和配置文件默認的寫法一樣,求助大佬,看看是哪里的問題?

回答
編輯回答
菊外人

我記得nginx.conf默認有幾條基礎(chǔ)的server規(guī)則,你把它都清掉,只留下include vhosts.conf試試~

附上我自己的配置:

nginx.conf

worker_processes 1;
error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile    on;
    tcp_nopush  on;
    keepalive_timeout 65;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout    300;
    fastcgi_read_timeout    300;
    fastcgi_buffer_size     128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 32k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6].";

    server_names_hash_bucket_size 128;
    client_max_body_size     100m;
    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;

    include vhosts.conf;
}

vhosts.conf

server {
    listen       80;
    server_name  localhost;

    root    "X:/www";
    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    error_page 404              /404.html;
    error_page 500 502 503 504  /50x.html;

    location = /50x.html {
        root html;
    }

    location ~ \.php(.*)$  {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include fastcgi_params;
        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;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

(其實基本沒加什么,都是原來那些……)

2017年3月9日 11:05