小编Car*_*ero的帖子

Nginx 上游不适用于 docker 部署堆栈

我正在尝试使用 docker 部署堆栈。

这是我的堆栈的工作原理:

  • nginx-proxy(将用户请求重定向到好的容器)
  • 网站(简单的 nginx 服务网站)
  • api(django 应用程序,使用 gunicorn 启动)
  • nginx-api(提供静态文件和上传的文件,如果是端点,则重定向到 API 容器)

这是我的 docker-compose.yml:

version: '3.2'

services:
    website:
        container_name: nyl2pronos-website
        image: nyl2pronos-website
        restart: always
        build:
          context: nyl2pronos_webapp
          dockerfile: Dockerfile
        volumes:
            - ./logs/nginx-website:/var/log/nginx
        expose:
            - "80"
        deploy:
            replicas: 10
            update_config:
                parallelism: 5
                delay: 10s

    api:
        container_name: nyl2pronos-api
        build:
            context: nyl2pronos_api
            dockerfile: Dockerfile
        image: nyl2pronos-api
        restart: always
        ports:
            - 8001:80
        expose:
            - "80"      
        depends_on:
            - db
            - memcached
        environment:
            - DJANGO_PRODUCTION=1
        volumes:
            - ./data/api/uploads:/code/uploads
            - ./data/api/static:/code/static

    nginx-api:
        image: nginx:latest …
Run Code Online (Sandbox Code Playgroud)

nginx docker docker-compose docker-swarm

5
推荐指数
1
解决办法
1231
查看次数

第一次如何设置mysql root密码

我在 Linux 上,从未安装过数据库管理系统,但是当我在终端中输入时,mysql --version 我得到了mysql Ver 15.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2.

当我不输入任何密码时,我可以无需密码地连接到数据库mysql

同时,我安装了 Adminer,我想使用它替代 phpmyadmin 来管理我的数据库,但我无法连接自己,我在浏览器中收到以下错误Access denied for user 'root' @ 'localhost'

我尝试了在谷歌谷歌上找到的所有方法来创建根密码,但我不能。

我尝试了这里提出的解决方案:

还有许多订单链接。

如何为mysql设置root密码以在Adminer中使用它

mysql

4
推荐指数
1
解决办法
1万
查看次数

节点:错误选项:--experimental-worker

我正在尝试在node.js.

const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
    // This code is executed in the main thread and not in the worker.

    // Create the worker.
    const worker = new Worker(__filename);
    // Listen for messages from the worker and print them.
    worker.on('message', (msg) => { console.log(msg); });
} else {
    // This code is executed in the worker and not in the main thread.

    // Send a message to the main thread.
    parentPort.postMessage('Hello world!'); …
Run Code Online (Sandbox Code Playgroud)

javascript worker-thread node.js

4
推荐指数
1
解决办法
2466
查看次数

SOLID 设计原则:Liskov 替换原则和依赖倒置原则

只是对 Stack Overflow 和 Microsoft 开发社区的一个想法和一个关于称为 SOLID 的 OO 软件设计原则的问题。请问Liskov替换原则和依赖倒置原则有什么区别?我已经考虑了一段时间,但我不确定其中的区别。请问你能告诉我吗?非常欢迎任何想法/反馈。

liskov-substitution-principle solid-principles dependency-inversion

3
推荐指数
1
解决办法
1755
查看次数

Rust匹配不起作用

我正在做一些生锈的简单的东西...只是触摸你知道的一些地方.

所以我正在玩命令行参数,我不能通过这个:

use std::os::args;

fn main(){

    let arg1 = args().get(1).to_str();

    let help_command = "help";

    if args().len() == 1 {
            println!("No arguments.");
    }

    else if args().len() == 2 {

            match arg1 {
                    help_command => println!("Do ..."),
                    _    => println!("no valid argument")
            }

    }

}
Run Code Online (Sandbox Code Playgroud)

我不能编译......错误是:

main.rs:17:4: 17:5 error: unreachable pattern
main.rs:17                      _    => println!("no valid argument")
                                ^
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)

另外,我正在使用Rust 0.11.0-pre-nightly.

谢谢

编辑:另外,如果我采用这种方法:

match arg1 { 
    "help" => { /* ... / }, 
    _ => { / …
Run Code Online (Sandbox Code Playgroud)

match rust

2
推荐指数
1
解决办法
1092
查看次数

axios.post 导致错误请求 - grant_type:'client_credentials'

我的 axios POST 方法无法正常工作。虽然调用语法似乎是正确的,但我想在我的具体案例中存在一些根深蒂固的问题。我正在尝试使用 grant_type=client_credentials 获取访问令牌,使用对固件 IDM 服务器的 POST 请求。调用结果为400: bad request

curl 命令效果很好。当我使用简单的 http 请求时,似乎存在 CORS 违规,因此我切换到使用 node.js。我通过在单独的正文中发送数据来尝试 axios,它也不起作用,然后有人建议使用 axios.post 在呼叫中发送数据,它也以同样的问题结束。注意:grant_type=password然而,我尝试过,也遇到了同样的命运。

axios.post('https://account.lab.fiware.org/oauth2/token',{ 
'grant_type':'client_credentials'},{
headers: 
{
'Content-Type':'application/x-www-form-urlencoded',     
'Authorization': 'Basic xxxx'   
}

}).then((response) => {
    console.log(response);
    }).catch((error) =>{
    console.log(error.response.data.error);
    })
Run Code Online (Sandbox Code Playgroud)

我希望获得访问令牌,但是,我收到错误 400,如下所示:

{ message: 'grant_type missing in request body: {}',
code: 400,
title: 'Bad Request' }
Run Code Online (Sandbox Code Playgroud)

post node.js oauth-2.0 fiware axios

2
推荐指数
1
解决办法
5003
查看次数

ArgumentCountError:函数 phpunit 的参数太少

我正在尝试使用创建一些编程测试phpUnit。我需要使用数据提供程序,但每次尝试时,它都会引发错误。我什至使用 文档中给出的示例phpUnit

 /**
 * @dataProvider additionWithNonNegativeNumbersProvider
 */
public function testAdd($a, $b, $expected)
{
    $this->assertSame($expected, $a + $b);
}

public function additionWithNonNegativeNumbersProvider()
{
    return [
        [0, 1, 1],
        [1, 0, 1],
        [1, 1, 3]
    ];
}
Run Code Online (Sandbox Code Playgroud)

我期望输出是:

There was 1 failure:
1) DataTest::testAdd with data set #3 (1, 1, 3)
Failed asserting that 2 is identical to 3.
Run Code Online (Sandbox Code Playgroud)

但它是:

ArgumentCountError : Too few arguments to function controllerTests::testAdd(), 0 passed in phar://C:/xampp/htdocs/2019-1-qa-grupo1/myss/Tests/phpunit-8.1.2.phar/phpunit/Framework/TestCase.php on line 1172 and exactly 3 …
Run Code Online (Sandbox Code Playgroud)

php phpunit

2
推荐指数
1
解决办法
6308
查看次数

致命错误LNK1168:无法打开filename.mexw64进行写入

我正在使用Visual Studio 2015编写c ++ / CUDA代码,以生成与MATLAB集成的mex文件。

当我通过MATLAB控制台运行mex文件,然后尝试在VS上再次对其进行编译时,出现此错误:

链接:致命错误LNK1168:无法打开filename.mexw64进行写入

  • 关闭MATLAB并再次打开程序即可解决该问题。

有谁知道不涉及关闭MATLAB的解决方案吗?

c++ matlab cuda mex visual-studio

2
推荐指数
1
解决办法
103
查看次数

简单的Flask项目运行缓慢

我正在开始使用 Flask,并发现一些奇怪的延迟问题。

Flask 代码是最简单的“Hello World!” 如下:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello World!"
if __name__ == "__main__":
    app.run()
Run Code Online (Sandbox Code Playgroud)

它使用VM和Gunicorn安装在远程Ubuntu 18服务器上,如下所示:

gunicorn -b 0.0.0.0:5000 app:app --reload
Run Code Online (Sandbox Code Playgroud)

我正在使用Python“requests”库在Windows 10下调用服务器,如下所示:

import requests, time

url = 'http://vps.XXXXX.ssdhosts.com.au:5000/'

t0 = time.time()
response = requests.get(url)                       
t1 = time.time()
total = t1-t0
print("Simple get request took " , total)
Run Code Online (Sandbox Code Playgroud)

问题是调用远程函数的时间总是在 0.7 秒到 1 秒之间,对于这样一个简单的函数来说,这似乎很慢。通过阅读类似的部署,我的印象是这个调用应该要快得多。

这个功能可以加速吗?

我努力了:

  • 硬编码 IP 地址
  • 禁用 IPv6
  • 在 app.run() 中设置 threaded=True
  • 从浏览器调用网址

这些都没有任何区别。

另外,服务器在澳大利亚,而我在英国。这会导致速度变慢吗?

python flask

1
推荐指数
1
解决办法
3898
查看次数