Jump to content

NGINX and REST API


Recommended Posts

Anyone having some experience with NGINX and can help me setting up my API location, so I can pass the API Token using headers rather than as a part of the URL?

Have been looking on sites like Stackoverflow for a potential solution, yet none of the suggestions has worked.

The exact message I get is the one on the attached image.

 

upstream php_backend {
    server  unix:/var/run/php-fpm_webapp.sock;
}


server {

    # Basic server configuration
    listen       443 ssl;
    server_name  XXXXXXXXXX XXXXXXXXXX;

    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;
    include snippets/real_ip_cf.conf;

    root         XXXXXXXXXX;
    index        index.php;

    # Maximum allowed upload size
    client_max_body_size 100M;

    # Logging
    access_log  XXXXXXXXXX/access.log main;
    error_log   XXXXXXXXXX/error.log error;

    # Friendly URL "rewrite" rules
    location / {
        try_files   $uri $uri/ @ips;
    }

    # Configuration includes
    include /etc/nginx/includes/ips/protect_upload_directories;
    include /etc/nginx/includes/deny_dotfiles;
    include /etc/nginx/includes/stub_status;
    include /etc/nginx/includes/php_fpm_status;

    # Assign cache headers to static files
    location ~* ^.+\.(?:jpg|jpeg|gif|css|png|js|ico|xml|htm|swf|cur)$ {
        # If the static resource doesn't exist, pass off to IPS' 404 handler
        try_files   $uri @ips404;

        access_log  off;
        expires     2w;
    }

    # Lock down access to the AdminCP
    location ~ ^/admin/.+\.php$ {
        #allow         127.0.0.1;
        #deny          all;
        #auth_basic    "This page is restricted to administrators";
        #auth_basic_user_file $document_root/admin/.htpasswd;

        try_files   $uri @ips404;

        include         /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass    php_backend;
    }

    # Execute the requested PHP script if it exists, otherwise pass off to IPS
    location ~ \.php$ {
        try_files   $uri @ips;

        include             /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass        php_backend;

        fastcgi_buffers     38 4k;
        fastcgi_buffer_size 16k;
    }

    # Pass off not found errors to IPS' 404 handler
    location @ips404 {
        include             /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass        php_backend;

        fastcgi_param       SCRIPT_FILENAME  $document_root/404error.php;
        fastcgi_param       SCRIPT_NAME      404error.php;
    }

    # Send rewritten requests directly to IPS
    location @ips {
        include             /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass        php_backend;

        fastcgi_param       SCRIPT_FILENAME  $document_root/index.php;
        fastcgi_param       SCRIPT_NAME      /index.php;

        fastcgi_buffers     38 4k;
        fastcgi_buffer_size 16k;
    }

    # IPS API
    location /api/ {
        try_files $uri $uri/ @api;
    }

    # IPS API LOCATION
    location @api {
        rewrite ^ /api/index.php?$args last;
    }

}

server {
    listen 80;

    server_name XXXXXXXXXX XXXXXXXXXXX;

    return 302 https://$server_name$request_uri;
}

Some information has been replaced with "XXXXXXXXXX" due privacy/security.

image.png.b944cab7b815150c09ec231d49f46188.png

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...