causefx / Organizr

HTPC/Homelab Services Organizer - Written in PHP
GNU General Public License v3.0
5.19k stars 292 forks source link

Error nginx v1 to v2 #1486

Closed fana13 closed 4 years ago

fana13 commented 4 years ago
Organizr Version: V 1.x to V2
Branch: Master
WebServer: Nginx
Operating System: Debian Buster

Problem Description:

I've got an error when I want to migrate V1 to V2 Issue come to my nginx configuration but I don't know how to solve it. There is my config :

location /Organizr {
                root /var/www/;
                include /etc/nginx/conf.d/php.conf;
                include /etc/nginx/conf.d/cache.conf;

        }

If I add the block for api v2 like this, it doesn't work...


location  /Organizr {
                root /var/www/;
                include /etc/nginx/conf.d/php.conf;
                include /etc/nginx/conf.d/cache.conf;

        }
location /api/v2 {
      try_files $uri /api/v2/index.php$is_args$args;
}

Have you any ideas to correctly write my nginx conf ? Thanks


Reproduction Steps:

Errors on screen? If so paste here:

HalianElf commented 4 years ago

Your api block should also have the base url (and probably needs the root and php block since you have them in the Organizr location block):

location /Organizr/api/v2 {
      root /var/www/;
      include /etc/nginx/conf.d/php.conf;
      try_files $uri /Organizr/api/v2/index.php$is_args$args;
}
fana13 commented 4 years ago

Thanks for your help but it doesn't work anymore I've got this web page on https://mydomain/Organizr/api/v2

response |   result | "error" message | "Endpoint Not Found or Defined" data |   endpoint | "/Organizr/api/v2" method | "GET"

HalianElf commented 4 years ago

That's the correct response if you don't give it an endpoint... try https://mydomain/Organizr/api/v2/status

fana13 commented 4 years ago

I've got this :

response  
result "success"
message null
data  
status "ok"
api_version "2.0"
organizr_version "2.1.0"

Nothing more

HalianElf commented 4 years ago

So it's working...?

PowerShellCrack commented 4 years ago

Everything was working until I upgraded to 2.1.0 and I'm running on: OS: Windows 10 2004 Browser: Edge Chromium Organzr Type: Nginx 1.19.4 PHP: 7.3.9

I followed the doc: migration

I changed the nginx.config to:

  worker_processes  1;
  events {
    worker_connections  1024;
  }

  http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #gzip  on;

    server {
        listen       8282;
        server_name  localhost;
        root  /Organizr/www/organizr/html;
        index index.php index.html index.htm;       

        #charset koi8-r;

        location /api/v2 {
            try_files $uri /api/v2/index.php$is_args$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
  }

when I restart the nssm and php service and open a page in the browser it downloads the index.php file instead of rendering it.

I went to the http://localhost:8282/api/v2/status and originally it said { "response": { "result": "success", "message": "Ran update function for version: 2.1.0", "data": null } }

But still, nothing worked. I decided to point nginx root to the html.backup folder to use the old version (and I changed the config back to (location ~ \.php${ }). Site came back up and I tried to log in and it said login Error. The login WAS using plex server oauth to login. now what....

I decided to remove everything and start from scratch. I downloaded the v2 zip from the sit, extracted it to the organizr folder, renamed it to html, and restarted the services.

http://localhost:8282/api/v2/status: { "response": { "result": "success", "message": null, "data": { "status": "ok", "api_version": "2.0", "organizr_version": "2.1.0" } } }

http://localhost:8282/api/v2/update/migrate/2.1.0 { "response": { "result": "error", "message": "Not Authorized", "data": null } }

error.log: 2020/10/28 23:29:35 [error] 1464#10364: *1 CreateFile() "C:/Organizr/www/organizr/html/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8282", referrer: "http://localhost:8282/api/v2/update/migrate/2.1.0"

I'm not sure what else to do. The main page just downloads a PHP file.

HalianElf commented 4 years ago

You screwed up your php block when you added the api block:

server {
    listen       8282;
    server_name  localhost;
    root  /Organizr/www/organizr/html;
    index index.php index.html index.htm;       

    #charset koi8-r;

    location /api/v2 {
        try_files $uri /api/v2/index.php$is_args$args;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}
PowerShellCrack commented 4 years ago

Oh man am I an idiot. I was able to launch the website. thanks

fana13 commented 4 years ago

So it's working...?

No, still can't access to my Organizr web page

HalianElf commented 4 years ago

Well, we need more details then because the api block is working as it's supposed to based on your previous response with what status gave you.

causefx commented 4 years ago

what happens when you access: https://mydomain/Organizr

fana13 commented 4 years ago

Well, we need more details then because the api block is working as it's supposed to based on your previous response with what status gave you.

I give you my nginx conf, it's a little mess. Think it's better to understand my issue

server { listen 80 default_server; servername ; rewrite ^(.*) https://mydomain$1 permanent; }

server {

listen 443 ssl;
server_name mydomain;
ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem;

location ^~ / {
root /var/www/base;
include /etc/nginx/conf.d/php.conf;
include /etc/nginx/conf.d/cache.conf;
satisfy any;
allow all;
}

location /sb { try_files /sb/$uri /sb/index.php$is_args$args; } root /var/www/; location ~ .php$ { fastcgi_index index.php; try_files $fastcgi_script_name =404; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php7.4-fpm.sock; auth_basic ""; auth_basic_user_file "/etc/nginx/passwd/xxx_passwd"; } location ~* .(jpg|jpeg|gif|css|png|js|map|woff|woff2|ttf|svg|eot)$ { expires 30d; access_log off; }

location ^~ /Organizr/api/v2 { root /var/www/; include /etc/nginx/conf.d/php.conf; try_files $uri /Organizr/api/v2/index.php$is_args$args; }

}

fana13 commented 4 years ago

Conflict with this part:

location ^~ / { root /var/www/base; include /etc/nginx/conf.d/php.conf; include /etc/nginx/conf.d/cache.conf; satisfy any; allow all; }

Now everthing it's OK. Thanks for your help.