我需要配置nginx为两个PHP框架在同一个域的不同位置。example.com/-codeigniter(根 /var/www/html/codeigniter)
example.com/api-laravel 5.2(根 /var/www/html/laravel)
这里是我的例子,但它们不起作用。
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html/codeigniter;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location /api {
root /var/www/html/laravel/public/;
index index.php index.html index.htm;
try_files $uri $uri/ index.php?$query_string;
location ~ \.php$ {
try_files $uri /index.php =500;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
}
}
在第一个示例中,编码器在路由示例中完美工作。com/*,但laravel不在路线上工作:
/api - codeigniter return 404 page not found,
/api/index.php - laravel return 404 because this page not exists,
/api/user/ -codeigniter also return 404 page
此配置也不起作用:
server {
listen 80;
server_name example.com;
root /var/www/;
index index.php index.html index.htm;
charset utf-8;
access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/examplw.com-error.log error;
sendfile off;
client_max_body_size 100m;
location /api {
root /var/www/html/laravel/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
try_files $uri /index.php =500;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
location / {
root /var/www/html/codeigniter;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
}
例如,此配置也不起作用。例如,com-codeigniter可以完美地工作。com/api-codeigniter返回404示例。com/api/index。php-laravel返回404
有人能帮我找到正确的配置方法吗?
看看这个:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
# CodeIgniter
location / {
try_files $uri $uri/ /index.php?$uri&$args;
}
# deny access to .htaccess files
location ~ /\.ht {
deny all;
}
# Laravel
location /api {
try_files $uri $uri/ /api/index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
将您的Laravel索引文件(index.php
)放入目录/public/api
更改索引中的目录。php
调用正确的引导文件
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
require __DIR__.'/../../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../../bootstrap/app.php';
本文向大家介绍Nginx下配置codeigniter框架方法,包括了Nginx下配置codeigniter框架方法的使用技巧和注意事项,需要的朋友参考一下 原来在winserver+Apache环境下工作良好的一个微信公众号后台迁移到阿里云(环境:Ubuntu 64位 | PHP5.4 | Nginx1.6)下却频出 404,403,只能访问CI routes.php中设置的默认控制器等问题,后来
如何在NGINX配置中为两个位置设置相同的规则? 我尝试了以下方法 但是nginx reload抛出了这个错误:
Dokuwiki在Apache上安装很简单,这里说说在Nginx的设置。 一、禁止DOKUWIKI敏感目录的访问 在Apache下,因为各目录下的.htaccess文件已经设置好了,所以无需任何修改就可以用,但是Nginx下不仅要禁止目录访问,还要加密目录,否则输入文件名依然可以下载。加密目录的方法请参看LNMP下为Nginx目录设置访问验证的用户名密码。下面是配置文件。 location ^~
本文向大家介绍Nginx同时支持Http和Https的配置详解,包括了Nginx同时支持Http和Https的配置详解的使用技巧和注意事项,需要的朋友参考一下 现在的网站支持Https几乎是标配功能,Nginx能很好的支持Https功能。下面列举一个配置同时支持Http和Https的功能。 需要注意的是:既然选择使用Https,就是为了保证通信安全,那么就没必要再用Http进行通信了。在URL中还
Nginx 说明 Nginx 是一个很强大的高性能 Web 和反向代理服务器,常被我们用作负载均衡服务器,也可以作为邮件代理服务器 Nginx WIKI:https://zh.wikipedia.org/zh/Nginx Nginx 百科:http://baike.baidu.com/item/nginx Nginx 官网:http://nginx.org/en/ Nginx 官网下载:http:
嗨,我正在为BackOffice创建laravel,为前端创建Api。 在前端,我使用vuejs。 如何设置nginx 如果查找路径/管理- 这是我现在用的 这是我的文件夹结构 *****更新***** 这是我的拉威尔。形态 nginx错误。日志显示/etc/nginx/sites enabled/laravel。conf”在/etc/nginx/nginx.conf:62中失败(40:符号链接级