Heim  >  Fragen und Antworten  >  Hauptteil

golang – Verwenden Sie den Nginx-Reverse-Proxy, um in Go geschriebene Websites bereitzustellen.

Dies ist der Pfad meines Go-Sprachprojekts (MVC): /home/demo/goproj/src/Test Es lauscht auf Port 8080. Wie schreibe ich die Nginx-Konfigurationsdatei? ? Ich habe es mehrmals konfiguriert, aber es ist immer noch falsch. „location /{}“ oder schreiben Sie so: „location /Test {}“

習慣沉默習慣沉默2712 Tage vor836

Antworte allen(2)Ich werde antworten

  • 伊谢尔伦

    伊谢尔伦2017-05-16 17:29:54

    简单版本:

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://localhost:8080;
    }
    

    一般静态文件由 nginx 提供,所以可以这样写

    root /home/demo/goproj/src/Test/public;
    try_files $uri/index.html $uri.html $uri @goapp;
    
    location @goapp {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://localhost:8080;
    }
    

    Antwort
    0
  • 大家讲道理

    大家讲道理2017-05-16 17:29:54

    server {
        listen 80;
        server_name 123.com;
    
        location / {
        proxy_pass    http://127.0.0.1:8080;
        proxy_redirect default;
            }
    }
    

    如果有2级目录则

            location /test {
            proxy_pass    http://127.0.0.1:8080;
            proxy_redirect default;
            }
    

    Antwort
    0
  • StornierenAntwort