在子文件夹中为Laravel配置nginx [英] Config nginx for Laravel In a subfolder

查看:66
本文介绍了在子文件夹中为Laravel配置nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧项目,现在需要新功能,我将使用laravel提供它, 一切都可以在apache的xampp中正常工作,但是我的服务器connginx向我显示访问被拒绝的消息并且无法访问我的路由,如果在mysite.com/2015中安装了laravel,我的站点配置应该是什么?我改变了吗? 我尝试过

I have and old project that now requires new functionality, I'm going to use laravel to provide it, everything in working ok in xampp with apache but my server con nginx show me access denied message and cant access my routes, how should be my site config should be if laravel is installed in mysite.com/2015 my site config is the following, what showld I change? I have tried

location /newsection/ { 
   try_files $uri $uri/ /newsection/public/index.php$request_uri;
}

但这会导致500错误

server {
    listen 80;
    server_name am2.aminversiones.com;
    root /home/forge/am2.aminversiones.com;

    # 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;

    client_max_body_size 300M;

    location / {
        #try_files $uri $uri/ /index.php?$query_string;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    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/am2.aminversiones.com-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;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }

    # version 1
    location ^~ /2015 {
        alias /home/forge/am2.aminversiones.com/2015/public;
        try_files $uri $uri/ @2015;
        location ~* \.php {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            include /etc/nginx/fastcgi_params;
        }
    }

    location @2015 {
        rewrite ^/2015/(.*)$ /2015/index.php/$1 last; # THIS IS THE IMPORTANT LINE
    }
    # end version 1

    # version 2
    # this is with `ln -s /home/tom/public_html/demos/demo1/public <document root>/demo1`
    location ~ /2015 {
        try_files /2015/$uri /2015/$uri/ /2015/index.php?q=$uri&$args;
    }
    # end version 2

    # PHP FPM configuration.
    location ~* \.php$ {
        fastcgi_pass                    unix:/var/run/php5-fpm.sock;
        include                             /etc/nginx/fastcgi_params;
        fastcgi_index                       index.php;
        fastcgi_split_path_info             ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO             $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED       $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME       $document_root$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
        deny all;
    }
}

推荐答案

好吧,我在/etc/nginx/sites-available/yourSite中的nginx服务器的子目录中找到了非常简单的配置和安装Laravel的解决方案配置文件,添加以下内容:

Well, I found a solution to very easy config and install Laravel in a subdirectory in a nginx server, in the /etc/nginx/sites-available/yourSite config file, add this:

location ^~ /laravel {
    alias /var/www/laravel/public;
    try_files $uri $uri/ @laravel;

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

location @laravel {
    rewrite /laravel/(.*)$ /laravel/index.php?/$1 last;
}

瞧,您的路线将按预期正常运行.

and voila, your routes will work normally how they should.

这篇关于在子文件夹中为Laravel配置nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆