我的目标是在单个域下放置两个或更多(将来)Laravel应用程序并执行别名,例如:http://domain-name/Lara-1和http://domain-name/Lara-2。 我在别名方面遇到麻烦,最后能够通过使用位置来实现,但现在,除了两个应用程序的根Laravel index.php之外,所有其他uris都会导致 404错误。 其次是我的网站可用/默认文件:
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
server_name Domain-IP;
location ^~ /Lara-1/ {
alias /var/www/Lara-1/public/;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
location ^~ /Lara-2/ {
alias /var/www/Lara-2/public/;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
如果是单个应用而不是两个,即只有Lara-1,当我把根作为 的/ var / WWW /拉拉-1 /公共/;一切正常。以上情况仅在app别名的情况下发生。可能是,我可能配错了。
以下是我的fastcgi_params文件:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
我是Nginx和Laravel的新手。感谢您的帮助!
答案 0 :(得分:0)
在试用和错误后,此应用程序正常运行。以下是我的Nginx默认文件在webroot目录下放置的2个Laravel应用程序的样子。 碰巧使用Nginx Url重写。希望它有所帮助!
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.php index.html index.htm;
server_name 172.3.21.1;
root /var/www/webroot/;
location /projectdev {
rewrite ^/projectdev/(.*)$ /projectdev/public/index.php?$1 last;
}
location /projectqa {
rewrite ^/projectqa/(.*)$ /projectqa/public/index.php?$1 last;
}
error_page 401 403 404 /404.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
}
location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
# Block web attacks
location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t)
{
return 444;
}
# Protect .ini files
location ~ /\.ini
{
access_log off;
log_not_found off;
deny all;
}
location ~ /\.xml {
deny all;
}
}