2016-08-22 72 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;