Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web UI on nginx + php-fpm #22

Closed
geerteltink opened this issue Mar 12, 2018 · 24 comments
Closed

Web UI on nginx + php-fpm #22

geerteltink opened this issue Mar 12, 2018 · 24 comments
Assignees
Labels

Comments

@geerteltink
Copy link

I'm building this inside a docker container. The build is good. Running from the CLI inside the container works fine. However when trying to open the web ui from http://localhost/_spx?SPX_KEY=dev it gives me an empty _spx file download.

Am I doing something wrong?

Dockerfile build instructions

  # SPX
  && git clone https://github.com/NoiseByNorthwest/php-spx.git /tmp/spx \
  && cd /tmp/spx \
  && phpize \
  && ./configure \
  && make \
  && make install \

spx.ini:

[spx]
; https://github.com/NoiseByNorthwest/php-spx#advanced-usage
extension=spx.so
spx.http_enabled       = 1
spx.http_key           = dev
spx.http_ip_whitelist  = 172.18.0.1,docker.for.win.localhost
spx.http_ui_assets_dir = /usr/share/misc/php-spx/assets/web-ui

Docker build log (located at the end).

@NoiseByNorthwest
Copy link
Owner

Thanks for reporting this issue.

There is no need to specify spx.http_ui_assets_dir despite the fact you have set the right one regarding the install prefix Installing SPX web UI to: /usr/share/misc/php-spx/assets/web-ui.

However can you check the content and permission bits (rx on directories and r on regular files) of /usr/share/misc/php-spx/assets/web-ui ?

I will try your dockerfile in the evening, and also add some logs to simplify debugging.

@geerteltink
Copy link
Author

Permissions look fine to me:

/usr/share/misc/php-spx/assets/web-ui # ls -lha
total 40
drwxr-xr-x    4 root     root        4.0K Mar 12 14:53 .
drwxr-xr-x    3 root     root        4.0K Mar 12 14:53 ..
drwxr-xr-x    2 root     root        4.0K Mar 12 14:53 css
-rw-r--r--    1 root     root       12.0K Mar 12 14:53 index.html
drwxr-xr-x    2 root     root        4.0K Mar 12 14:53 js
-rw-r--r--    1 root     root        8.2K Mar 12 14:53 report.html

@NoiseByNorthwest
Copy link
Owner

NoiseByNorthwest commented Mar 12, 2018

Is fpm running as root ? The permissions are granted to root only.

EDIT: in other words you might add something like a chgrp on this directory in the install process.

@geerteltink
Copy link
Author

geerteltink commented Mar 12, 2018

Yes, everything inside the docker container is run as root. In this case php-fpm only.

@NoiseByNorthwest
Copy link
Owner

IMHO this is on SPX side, I will add some logs this evening. SPX is supposed to intercept and serve any url starting with its prefix (_spx by default), this appears to be not the case in your setup.
In most cases if SPX does not intercept this url it is an authentication failure (ip or key).
What is your var_dump($_SERVER['REMOTE_ADDR']); ?

@geerteltink
Copy link
Author

var_dump($_SERVER['REMOTE_ADDR']); looks alright: '/_spx?SPX_KEY=dev'

I just looked at the source code and you are right. It should intercept the url, which is correct according the var_dump. I'm testing the permissions now.

@thinkspill
Copy link

FWIW, I also experienced the same thing under similar circumstances, php-fpm in a container. Looking forward to giving this a spin, it looks awesome. :)

@geerteltink
Copy link
Author

Turns out php-fpm is running as www-data in my container.

Changing permissions with chown -Rv www-data:www-data /usr/share/misc/php-spx didn't help.
And also chmod -Rv 0777 /usr/share/misc/php-spx didn't fix it.

So yes, some debug output would be helpful :)

@NoiseByNorthwest
Copy link
Owner

NoiseByNorthwest commented Mar 12, 2018

@xtreamwayz done, just checkout add_logs branch.

@geerteltink
Copy link
Author

@NoiseByNorthwest Where should it save the logs?

I tried with the settings I posted before and it's downloading the empty file. Can't find any logs.

I also tried the basics settings which result in a 404 and also no logs:

extension=spx.so
spx.http_enabled=1

@NoiseByNorthwest
Copy link
Owner

NoiseByNorthwest commented Mar 12, 2018

I use zend_error with E_NOTICE level, so on fpm's stderr, down to nginx error log on my setup.

@NoiseByNorthwest
Copy link
Owner

@xtreamwayz never forget sudo tail -f $(sudo find /var/log/ -mmin -1) :)

@NoiseByNorthwest
Copy link
Owner

add_logs merged.

@hacfi
Copy link

hacfi commented Mar 12, 2018

I’m gonna try this on OSX now. Ran into the same error that the page just loads forever and the request times out.

@hacfi
Copy link

hacfi commented Mar 12, 2018

@NoiseByNorthwest First of all: AMAZING tool! This is exactly the way I want it and I already prefer this over PhpStorm’s Xdebug profiler snapshot analysis.

Back to the issue: With latest master:
2018/03/12 23:44:32 [error] 234#0: *17 FastCGI sent in stderr: "PHP message: PHP Notice: spx: access granted: "127.0.0.1" IP with "dev" key in Unknown on line 0" while reading response header from upstream, client: 127.0.0.1, server: dev.project.local, request: "GET /_spx?SPX_KEY=dev HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm71.sock:", host: "dev.project.local". But the webserver never sends any data back and the browser keeps trying to load forever.

@thinkspill
Copy link

Also seeing the above with the latest build.

@NoiseByNorthwest
Copy link
Owner

@hacfi @thinkspill @xtreamwayz I've the feeling that there are 2 distinct issues:

  • 404 on Linux
  • endless request on macOS

is that right ? If so, @hacfi can you please open another issue for the endless request bug ?

I will try to make a minimal Dockerfile as a working fpm setup example.

@geerteltink
Copy link
Author

Enabled some more logging on my setup and I get this message as well:

2018/03/13 09:02:23 [error] 6#6: *1 FastCGI sent in stderr: "PHP message: PHP Notice:  spx: access granted: "172.18.0.1" IP with "dev" key in Unknown on line 0" while reading response header from upstream, client: 172.18.0.1, server: _, request: "GET /_spx?SPX_KEY=dev HTTP/1.1", upstream: "fastcgi://172.18.0.6:9000", host: "localhost"
172.18.0.1 - - [13/Mar/2018:09:02:23 +0000] "GET /_spx?SPX_KEY=dev HTTP/1.1" 200 206 "-" "browser data" "-"

I'm getting this on the webpage plus the file download:

Notice: spx: access granted: "172.18.0.1" IP with "dev" key in Unknown on line 0
HTTP/1.1 200 OK Content-Type: application/octet-stream Content-Length: 9223372036854775807

@NoiseByNorthwest
Copy link
Owner

It looks like the ftell here returns -1 as error (which is not handled). -1 is then interpreted as uint64 max value at formatting level.

I cannot tell right now why fopen pass and not the ftell.
I will add some logs and more I/O error handling this evening.

@NoiseByNorthwest
Copy link
Owner

@xtreamwayz @thinkspill @hacfi Just for your information it works fine with the trailing slash: http://localhost/_spx/?SPX_KEY=dev. I've made a typo in the README.

However, I will fix the issue with the version without the trailing slash (either not intercept it or 301).

@hacfi
Copy link

hacfi commented Mar 14, 2018

@NoiseByNorthwest Thanks..that was it - works on macOS with fpm + nginx!

@geerteltink
Copy link
Author

Brilliant. It's working now after some nginx config changes.

@aftabnaveed
Copy link

Sorry for commenting on a close issue. It still renders 404 for me on localhost http://localhost/_spx/?SPX_KEY=dev

and my configurations are:

extension=spx.so
spx.http_key="dev"
spx.http_ip_whitelist="0.0.0.0"

@NoiseByNorthwest
Copy link
Owner

@aftabnaveed the 0.0.0.0 does not have any special meaning (like a wildcard...) in SPX context. You have to put your actual IP(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants