将nginx用于proxy_pass到其他用户打开的本地端口

46scxncf  于 2023-03-29  发布在  Nginx
关注(0)|答案(1)|浏览(167)

我尝试在端口80上公开一个(streamlit)应用程序,它与nginx在同一台计算机上的端口8501上运行。streamlit应用程序由user 1启动,nginx.conf文件在安装时没有改变:

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/*;
}

#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;
#       }
#}

然后我在/etc/nginx/conf.d文件夹中的myserver.conf中指定服务器:

server {
    listen 80;
    location / {
        proxy_pass http://0.0.0.0:8501/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    access_log /var/log/nginx/access-8501.log;
    error_log /var/log/nginx/error-8501.log;
}

当我在Web浏览器中访问服务器地址时,我总是只看到nginx自己的主页,没有重定向到8501,错误日志中也没有任何内容。如果我清空整个nginx.conf文件,使其看起来像:

events {
}
http {
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        include /etc/nginx/conf.d/*.conf;
}

一切正常。那么到底发生了什么呢?我想像上面那样把Streamlit应用程序“隐藏”在代理后面,那么我的初始设置有什么问题呢?

svdrlsy4

svdrlsy41#

它与此目录/etc/nginx/sites-enabled/中的另一个.conf文件相关,因为在nginx.conf中包含此目录。

include /etc/nginx/sites-enabled/*;

您可以注解这一行或删除该.conf文件,然后一切正常。

rm -f /etc/nginx/sites-enabled/default.conf

相关问题