2015-01-05 3 views
4

У меня есть и старый проект, который теперь требует новых функций, я собираюсь использовать laravel для его предоставления, все работает нормально в xampp с apache, но мой сервер con nginx показывает мне доступ запрещен сообщение и не могу получить доступ к моим маршрутам, как должен быть мой конфигуратор сайта, должен быть, если laravel установлен в mysite.com/2015, моя конфигурация сайта - это следующее, что showld я меняю? Я попыталсяКонфигурация nginx для Laravel В подпапке

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

ответ

10

Ну, я нашел решение очень легко конфигурации и установить Laravel в подкаталоге на сервере Nginx, в/и т.д./Nginx/сайты-доступные/YourSite конфигурационный файл, добавьте это:

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

и вуаля, ваши маршруты будут работать в обычном режиме, как они должны.

+0

Это устранена проблема, я имел в течение нескольких дней в настоящее время. Спасибо – cfv1000

+0

Это отлично работает, но если да, то: http://www.example.org/laravel/?var=12345 это даст мне ошибку 404. Любые идеи, как их решить, привет! – Alberto

+0

@Alberto не забудьте перезагрузить nginx и php5-fpm – Lu32

0

это не сработало для меня, поэтому я получил другое решение.

  1. я создал «нормальный» домен Laravel, пункт http://generic.laravel корня/мой/Laravel/путь/общественный

  2. После этого я создал место на реальном домен проксировании к моему родовому Laravel :

    location /laravel { 
        rewrite /laravel/?(.*)$ /$1 break; 
        proxy_pass http://generic.laravel; 
    

    }

  3. к сожалению, Laravel собирается использовать URL http://generic.laravel для создания ссылок. Вы можете решить, что после этого шаги Laravel: Change base URL?

-1

пожалуйста, используйте:

server { 
client_body_in_file_only clean; 
client_body_buffer_size 32K; 

client_max_body_size 300M; 

sendfile on; 
send_timeout 300s; 
# Port that the web server will listen on. 
#listen   80; 

# Host that will serve this project. 
server_name  tsolar.com; 

# Useful logs for debug. 
access_log  /var/log/nginx/tsolar.com-access.log; 
error_log  /var/log/nginx/tsolar.com-error.log; 
rewrite_log  on; 

# The location of our projects public directory. 
root   /home/tom/public_html/demos/; 

# Point index to the Laravel front controller. 
index   index.php; 

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { 
access_log off; 
expires max; 
} 

location/{ 

    # URLs to attempt, including pretty ones. 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
} 

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

# version 1 
location ^~ /demo1 { 
    alias /home/tom/public_html/demos/demo1/public; 
    try_files $uri $uri/ @demo1; 

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

location @demo1 { 
    rewrite ^/demo1/(.*)$ /demo1/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 ~ /demo1 { 
    try_files /demo1/$uri /demo1/$uri/ /demo1/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; 
} 

# Set header expirations on per-project basis 
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ { 
    expires 365d; 
} 

}

+0

Это может решить проблему OP, но это полная конфигурация. Это не помогает выяснить, что не так в ситуации ОП и что именно решает проблему. Можете ли вы сделать эти пункты более ясными и более явными? –

Смежные вопросы