【问题标题】:How to set document root to load Laravel application using Nginx?如何设置文档根目录以使用 Nginx 加载 Laravel 应用程序?
【发布时间】:2015-05-01 22:53:39
【问题描述】:

我的网站一直显示 phpinfo();当我降落在上面时

  • 我的根应该是:/home/forge/aveniros/public
  • 我不确定在哪里设置它。
  • 我决定在以下位置配置我的设置:~/etc/nginx/sites-available/default

server {

    listen 80 default_server;
    server_name
    default;
    root / home / forge / aveniros / public;
    index index.html index.htm index.php;

    #
    FORGE SSL(DO NOT REMOVE!)# ssl_certificate;#
    ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf - 8;

    location / {
        try_files $uri $uri / /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log /
        var / log / nginx /
        default -error.log error;

    error_page 404 / index.php;

    location~\.php$ {
        fastcgi_split_path_info ^ (. + \.php)(/.+)$;
            fastcgi_pass unix: /var/run / php5 - fpm.sock; fastcgi_index index.php; include fastcgi_params;
        }

        location~/\.ht {
        deny all;
    }
}

然后,我保存后运行sudo service nginx restart。 似乎没有任何效果。

有人可以告诉我我在这里做错了什么吗?

【问题讨论】:

  • 只留下一个index index.php;
  • 现在我得到No input file specified. !!!!

标签: php linux laravel nginx laravel-5


【解决方案1】:

你需要将你的服务器名称设置为_,目前你只监听默认名称的请求。

server_name  _;

【讨论】:

  • 所以我不能将其保留为默认值,对吗?另外,如何找到我的服务器名称?是 linode 中的名字吗?
【解决方案2】:

使用这个虚拟主机

server {
listen       80;
server_name  project.dev;
root /var/www/directory/project/public;

access_log /var/log/nginx/access.log;
error_log  /var/log/nginx/error.log;

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

location ~ \.php/?(.*)$ {

    fastcgi_connect_timeout 3s;     # default of 60s is just too long
    fastcgi_read_timeout 10s;       # default of 60s is just too long

    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index  index.php;

    include fastcgi_params;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass   unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
} 
}

【讨论】:

    【解决方案3】:

    我的网站正在运行。这是我的设置:

    文件路径:~/etc/nginx/sites-available/default

    server {
        listen 80 default_server;
        server_name default;
        root /home/forge/aveniros/public;
    
        #HTTP Authentication Configuartion
        auth_basic "Restricted";
        auth_basic_user_file /home/forge/aveniros/.htpasswd;
    
        # FORGE SSL (DO NOT REMOVE!)
        # ssl_certificate;
        # ssl_certificate_key;
    
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
        index index.html index.htm index.php;
    
        charset utf-8;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        access_log off;
        error_log  /var/log/nginx/default-error.log error;
    
        error_page 404 /index.php;
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-11
      • 1970-01-01
      • 2014-11-16
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2014-02-15
      • 2015-06-01
      相关资源
      最近更新 更多