nginx - Nginx slim框架一直指向根文件夹中的主索引
问题描述
我正在尝试在 nginx 网络服务器上设置 slimframework。以下是我目前的设置。我正在使用苗条/苗条的骨架。每当我运行例如http://myip/apiv1时,它都会指向 /var/www/html 中的 index.php。即使我运行任何示例http://myip/apiv1/token也与上面相同。我尝试更改根目录 /var/www/html/apiv1/public; 别名/var/www/html/apiv1/public;一样的。nginx 还需要什么特殊设置。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server_tokens off;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/blockuseragents.rules;
limit_conn_zone $binary_remote_addr zone=addr:5m;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
#root /usr/share/nginx/html;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ index.php?$query_string;
}
location /apiv1 {
root /var/www/html/apiv1/public;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 444;
}
limit_conn addr 1;
}
解决方案
推荐阅读
- postgresql - 如何将 HashMap 作为 JSON 类型插入 PostgreSQL?
- javascript - 如何在本机(Objective-C)中为 WKWebView 获取 JS 对象?
- javascript - Vue:将元素推送到对象中的数组
- android - 如何在 Termux 中使用 Keybase Git 存储库
- oracle - Oracle PLSQL:两个不同数据库的不同行为
- javascript - 如何在html表单提交上运行服务器端功能
- linux - cp : 没有这样的文件或目录 bash 脚本
- javascript - 编写测试以验证 jest 中的对象属性(NodeJs)
- c# - 如何使用 Xamarin Forms Shell 在 iOS 中的 Tabbar 行和图标之间添加空格?
- security - 强化令人失望的扫描行为