首页 > 解决方案 > 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;


    }

标签: nginxslim

解决方案


推荐阅读