在nginx上重写plex媒体服务器URL?

时间:2014-04-23 12:28:31

标签: nginx rewrite

我在nginx中重写url的知识非常有限。我有一个在nginx上运行的plex媒体服务器,我可以使用http://domain.com/web/index.html访问仪表板,我在github上找到这些配置:

upstream plex-upstream {
    server plex-server.example.com:32400;
}

server {
listen 80;
server_name domain.com

    location / {
                if ($http_x_plex_device_name = '') {
                      rewrite ^/$ http://$http_host/web/index.html;
}

            proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect off;

                proxy_set_header Host $http_host;
            proxy_pass http://plex-upstream;
}
}

我想要删除/web/index.html,所以当我转到http://domain.com时,PMS信息中心将会加载。我已经尝试了一些班轮重写规则,但都失败了。感谢。

1 个答案:

答案 0 :(得分:2)

我不是nginx专家,但我有类似的问题。 不同之处在于我没有尝试将domain.name/别名为domain.name/web/, 我的目标是将domain.name/plex/别名为domain.name/web/。 我正在使用我能找到的所有解决方案重定向到web / index.html,除了这个Configure Plex Media Server Reverse Proxy nginx Linux

这个问题唯一的一个问题是,如果你去网上/你会留在那里。

所以这是我令人毛骨悚然的工作解决方案:

upstream plex {
    server localhost:32400;
}

server {
    listen 80;
    server_name domain.name;
    server_name_in_redirect off;

    location / {
        proxy_pass http://localhost:8888;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # Enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }

    location /web/index.html {
      if ($http_x_should_not_redirect = ""){
        return 301 https://domain.name/plex/index.html;
      }

      proxy_pass https://plex;
      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_should_not_redirect $host;
    }

    location /web {
      proxy_pass https://plex;
      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_should_not_redirect $host;
    }

    location /plex {
      proxy_pass https://127.0.0.1/web;
      proxy_set_header X-should-not-redirect $host; 
    }



    location /transmission/rpc {
        proxy_pass http://localhost:9091;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # Enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }


    location /transmission/web {
        proxy_pass http://localhost:9091;

        proxy_pass_header  X-Transmission-Session-Id;
        proxy_set_header   X-Forwarded-Host $host;
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # Enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/dovgastreetnas.viewdns.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dovgastreetnas.viewdns.net/privkey.pem;       # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  }

希望这会对某人有所帮助。