我有一个旧项目现在需要新功能,我将使用 laravel 来提供它,在 xampp 中使用 apache 一切正常,但我的服务器 con nginx 显示访问被拒绝消息并且无法访问我的路由,我应该怎么做站点配置应该是如果 laravel 安装在 mysite.com/2015 我的站点配置如下,我更改了什么 showld?我努力了
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;
}
}
原文由 Lu32 发布,翻译遵循 CC BY-SA 4.0 许可协议
好吧,我找到了一个非常简单的配置解决方案,并将 Laravel 安装在 nginx 服务器的子目录中,在 /etc/nginx/sites-available/yourSite 配置文件中,添加以下内容:
瞧,你的路线将正常工作。