Nginx反向代理配置,实现端口转发(Cloudreve、NextCloud、QBittorrent、XUI)

本文介绍了如何使用Nginx反向代理配置,实现端口转发,用于Cloudreve、NextCloud、QBittorrent、XUI等服务。

Nginx反向代理配置,实现端口转发(Cloudreve、NextCloud、qBittorrent、XUI)

安装Nginx

1
2
apt update
apt install nginx

修改配置文件

  1. 要实现端口转发,仅需在 Virtual Host Configs后的 Server中添加对应配置即可。
  2. 每一个转发添加一组 Server, listen后的端口号为 80server_name为你的域名。
  3. proxy_pass后的地址为你要转发的服务地址。
  4. 例如:http://127.0.0.1:5212Cloudreve的本机默认地址。
  5. 如果要使用本地存储策略,请将 client_max_body_size的注释符删除,并更改大小为理论最大文件尺寸。
  6. 最简单的配置如下,添加一个 Server即可,xui_port为你的服务端口。
1
2
3
4
5
6
7
        server {
                listen 80;
                server_name xui.xxxxxx.cn;
                location / {
                        proxy_pass http://127.0.0.1:{xui_port};
                }
        }

Nginx基本命令

1
2
3
nginx
nginx -s stop
nginx -s reload

配置文件示例

  1. 以下为配置文件示例,实现了 CloudreveNextCloudQBittorrentXUI的端口转发。
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

        server {
                listen 80;
                server_name cloudreve.xxxxxx.com;

                location / {
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header Host $http_host;
                        proxy_redirect off;
                        proxy_pass http://127.0.0.1:5212;

                        # 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
                        client_max_body_size 50000m;
                }
        }

        server {
                listen 80;
                server_name xui.xxxxxx.com;

                location / {
                        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        #proxy_set_header Host $http_host;
                        #proxy_redirect off;
                        proxy_pass http://127.0.0.1:{xui_port};
                }

        }

        server {
                listen 80;
                server_name qbittorrent.xxxxxx.com;

                location / {
                        proxy_pass http://127.0.0.1:{qbittorrent_port};
                        proxy_http_version 1.1;
                        proxy_set_header X-Forwarded-Host $http_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;
                        http2_push_preload on;

                }
        }
   

        server {
                listen 80;
                server_name nextcloud.xxxxxx.com;

                location / {
                        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;
                        proxy_set_header X-Forwarded-Host $server_name;
                        client_max_body_size 8G;
                        proxy_pass http://127.0.0.1:{nextcloud_port};
                }
        }

}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}   
Written by VastCosmic & Post in 泠境
Explore the Infinity Cosmos.
Built with Hugo
Designed By VastCosmic with Hugo Theme Stack