多种服务的Ngnix配置问题

时间:2019-01-04 20:40:20

标签: nginx

我正面临Nginx的配置问题。我的目标是使用nginx的反向代理和SSL函数通过各种URL结尾访问服务器上的各种服务。

对于一项服务,它可以完美运行,但对于其他服务,我无法管理。 我想访问这样的服务:

https://example.com/service1/  should point to http://localhost:1000
https://example.com/service2/  should point to http://localhost:2000
https://example.com/service3/  should point to http://localhost:3000

(依此类推)

服务主要是grafana,opehab,frontail等。我试图使工作的代码如下:

#################################
#       NGINX Confiuration      #
#################################

## Redirection
server {
   listen                          80;
   server_name                     example.com;
   return 301                      https://$server_name$request_uri;
}

## Reverse Proxy to openHAB
server {
#    listen                          80;
   listen                          443 ssl;
   server_name                     example.com;
   add_header                      Strict-Transport-Security "max-age=31536000; includeSubDomains";

## Secure Certificate Locations
   ssl_certificate                 /etc/letsencrypt/live/example.com/fullchain.pem;
   ssl_certificate_key             /etc/letsencrypt/live/example.com/privkey.pem;


    location /start/ {
         return 301                      https://example.com/basicui/app;
    }

    location /tail/ { 
         proxy_pass                  http://localhost:9001;
    }

    location / {
        proxy_pass                              http://localhost:8081;
       # proxy_buffering                         off;  # openHAB supports non-buffering specifically for SSEs now
        proxy_set_header Host                   $http_host;
        proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto      $scheme;

## Password Protection
        auth_basic                              "Username and Password Required";
        auth_basic_user_file                    /etc/nginx/.htpasswd;
    }

## Let's Encrypt webroot location
   location /.well-known/acme-challenge/ {
       root                                    /var/www/example.com;
   }
}

# vim: filetype=conf

该配置应如何正确完成?

0 个答案:

没有答案