简体   繁体   English

Nginx 和 Ubuntu Server 18.04 上的 Dryscrape“找不到 XVFB”错误

[英]Dryscrape "Can Not Find XVFB" Error on Nginx & Ubuntu Server 18.04

I need a help about Dryscrape and XVFB.我需要有关 Dryscrape 和 XVFB 的帮助。 I'm using Dryscrape on my Flask application for web scraping from a javascript page.我在我的 Flask 应用程序上使用 Dryscrape 从 JavaScript 页面抓取网页。 If I serve it with python3 main.py and the app config app.run(host="0.0.0.0") everything works great at port 5000. But I have to use Nginx and uWSGI to serve my application on a domain.如果我使用python3 main.py和应用程序配置app.run(host="0.0.0.0")为它提供服务,一切都在端口 5000 上运行良好。但是我必须使用 Nginx 和 uWSGI 在域上为我的应用程序提供服务。 So, while I'm serving the app with Nginx, I get this error.因此,当我使用 Nginx 为应用程序提供服务时,出现此错误。

Sep 30 19:39:16 /address\ uwsgi[959]:   File "./scrape_manager.py", line 10, in get_details
Sep 30 19:39:16 /address\ uwsgi[959]:     dryscrape.start_xvfb()
Sep 30 19:39:16 /address\ uwsgi[959]:   File "/home/user/app/venv/lib/python3.6/site-packages/dryscrape/xvfb.py", line 8, in start_xvfb
Sep 30 19:39:16 /address\ uwsgi[959]:     xvfb = Xvfb()
Sep 30 19:39:16 /address\ uwsgi[959]:   File "/home/user/app/venv/lib/python3.6/site-packages/xvfbwrapper.py", line 41, in __init__
Sep 30 19:39:16 /address\ uwsgi[959]:     raise EnvironmentError(msg)

What should I do to fix this?我应该怎么做才能解决这个问题?

I found the solution.我找到了解决方案。

The problem was in the service file of Nginx.问题出在Nginx的服务文件中。

app.service应用服务

[Unit]
Description=uWSGI instance to serve app
After=network.target

[Service]
User=user
Group=www-data
WorkingDirectory=/home/user/app/app
Environment="PATH=/home/user/app/venv/bin"
ExecStart=/home/user/app/venv/bin/uwsgi --ini /home/user/app/app/app.ini

[Install]
WantedBy=multi-user.target

Actually the source of failure was the environment path, it's only one and it's the virtual environment of the application.实际上失败的根源是环境路径,它只有一个,它是应用程序的虚拟环境。 But Dryscrape needs to access XVFB from /bin or /usr/bin (check it, where does it exist).但是 Dryscrape 需要从 /bin 或 /usr/bin 访问 XVFB(检查它,它存在于何处)。 In this way, I had to extend environment paths with both to try and I added /usr/bin and /bin这样,我不得不扩展环境路径,同时尝试添加/usr/bin/bin

[Unit]
Description=uWSGI instance to serve app
After=network.target

[Service]
User=user
Group=www-data
WorkingDirectory=/home/user/app/app
Environment="PATH=/home/user/app/venv/bin:/usr/bin:/bin"
ExecStart=/home/user/app/venv/bin/uwsgi --ini /home/user/app/app/app.ini

[Install]
WantedBy=multi-user.target

This is the correct service file but one of them ( /bin or /usr/bin ) is may be unnecessary so you have to check the paths, where XVFB file executing from.这是正确的服务文件,但其中之一( /bin/usr/bin )可能是不必要的,因此您必须检查执行 XVFB 文件的路径。 If not sure, add /usr/bin and /bin too;如果不确定,也添加 /usr/bin 和 /bin; it'll work but if you are able to find the path, add only one like this below.它会起作用,但如果您能够找到路径,请仅在下面添加一个这样的路径。

Environment="PATH=/home/user/app/venv/bin:/usr/bin"

And also this status might be a tricky related to your user-group / user permissions too.而且这种状态也可能与您的用户组/用户权限有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM