将nginx设置为kestrel的代理服务器(ASP.Net Core)


0

我正在尝试设置ASP.NET核心环境来托管我的应用程序,但我遇到了nginx webserver的问题。当我尝试连接到我的域名时,我得到了502 Bad Gateway。Nginx应该只作为kestrel的代理服务器运行。

是我正在遵循的指南的链接。配置几乎是微软建议的配置我只是改变了每个环境不同的变量。

问题的一行是http://aspdotnethost;在nginx.conf配置的末尾。当我评论它时,我被重定向到默认的www位置。

那么这条线路实际上是如何工作的,如何管理它以正确地重定向到localhost:5000?

/etc/nginx/proxy.conf

proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header    X-Forwarded-Proto $scheme;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4k;

/etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    include    /etc/nginx/proxy.conf;
    limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s;
    server_tokens off;

    sendfile on;
    keepalive_timeout 29; # Adjust to the lowest possible value that makes sense for your use case.
    client_body_timeout 10; client_header_timeout 10; send_timeout 10;

    upstream aspdotnethost {
        server localhost:5000;
    }

    server {
        listen *:80;
        add_header Strict-Transport-Security max-age=15768000;
        return 301 https://$host$request_uri;
    }

    server {
        listen *:443    ssl;
        server_name     example.com *.example.com;

        #Redirects all traffic
        location / {
            proxy_pass  http://aspdotnethost;
            limit_req   zone=one burst=10;
        }
    }

}

Nginx配置检查:

[root@rs-zap353479-1 patrick]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

当我输入curl http://localhost:5000然后我得到返回的html文件。所以那部分应该在我的眼中找到。


如果你curl 'http://aspdotnethost'在CentOS主机上运行会怎么样?
Eugen Rieck

Name or service not known那么我应该知道名称或服务是什么?

编辑/etc/hosts以包含您的ASP主机的IP名称aspdotnethost(如您在nginx配置中所称)
Eugen Rieck

Answers:


0

像Eugen Rieck发表的评论我必须添加一个别名/etc/hosts

作为额外的步骤我需要指定proxy_temp_pathproxy.conf,创建路径和chown它是在nginx的运行(在我的情况下,用户nginx)。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.