2016-08-22 70 views
1

我在laravel開發了一個網站,我想將它安裝在運行nginx的本地機器上作爲Web服務器。下面是我的配置文件laravel的NGNIX服務器設置5.2

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root html; 
    index index.html index.php; 

    # Make site accessible from http://localhost/ 
    server_name localhost; 


    location/{ 
     root html; 
     index index.php; 
    } 

    location ~ .php$ { 
    root   html; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name; 
    include  fastcgi_params; 
    } 


} 

當我瀏覽http://localhost/mysite/運行C:/nginx/html/mysite/index.php

我要執行C:/ nginx的/ HTML/mysite的/公改爲/index.php文件。我該怎麼做?

+0

創建一個新的正則表達式位置塊,指向'mysite'並使用其中的'root'指令設置新的根目錄。 –

+0

如何我可以做到這一點,如果我想執行此文件第一C:/nginx/html/mysite/public/index.php – DOE

回答

1

從你的Nginx文件中,我將假設你的項目的根目錄是html,你所有的Laravel文件都在這個目錄下。

如果是這種情況,那麼你可以去http://localhost/mysite/public或將你的Nginx配置中的root目錄改爲html/public

如果這樣不起作用,請將root設置爲本地計算機上的完整路徑以訪問Laravel項目的公用文件夾。

編輯 嘗試:

root /c/nginx/html/mysite/public 

OR

root C:/nginx/html/mysite/public 
+0

我的文件是C:/ nginx/html/mysite /但我想執行是從C: /nginx/html/mysite/public/index.php – DOE

+0

@DOE看到我的編輯 – James

+0

目錄索引「C:\ nginx/html/mysite /」被禁止, – DOE

0

下面是我的配置:

server { 
    server_name  laravel.mydomain; 
    root    /home/me/domain/laravel.mydomain/public/; 

    location/{ 
     try_files $uri /index.php$is_args$args; 
    } 

    location ~ ^/index\.php(/|$) { 
     fastcgi_pass      unix:/run/php-fpm/php-fpm.sock; 
     fastcgi_split_path_info   ^(.+\.php)(/.*|$); 
     fastcgi_param PATH_INFO   $fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

     include  fastcgi_params; 
     internal; 
    } 
} 

只要改變root到您的public文件夾。

try_files確保當文件沒有直接存在於文件系統中時,所有內容都由index.php處理,它位於root路徑中。

0
You have to change only one line: Looks the final code in below 

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root C:/nginx/html/mysite/public; 
    index index.html index.php; 

    # Make site accessible from http://localhost/ 
    server_name localhost; 


    location/{ 
     root html; 
     index index.php; 
    } 

    location ~ .php$ { 
    root   html; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name; 
    include  fastcgi_params; 
    } 
} 

請仔細查看代碼。我已經改變了ony 根html到根C:/ nginx/html/mysite/public;