express – 将本地nginx服务器部署到公共ubuntu 16.04

前端之家收集整理的这篇文章主要介绍了express – 将本地nginx服务器部署到公共ubuntu 16.04前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试将我的本地Nginx服务器部署到公众. Nginx服务器作为我的node express应用程序的反向代理运行,该应用程序也在端口3000上本地运行.因此我创建了一个符号链接来自/ etc / Nginx / sites-available / express TO / etc / Nginx / sites-enabled /表达,所以我的配置文件叫做express,看起来像这样.

在/ etc / Nginx的/启用的站点 – /快递

upstream express_servers{
    server 127.0.0.1:3000;
}

server {

    listen 80;

        location / {
        proxy_pass http://express_servers;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

}

我已从已启用站点文件夹中删除了默认文件,但我没有更改我的Nginx.conf文件,如下所示

/etc/Nginx/Nginx.conf

user www-data;
worker_processes auto;
pid /run/Nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    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; # 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_disable "msie6";

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

我还使用ufw(简单防火墙)更改了我的防火墙设置,以允许在http访问(尤其是Nginx).我的ufw状态如下所示:

Status: active
Logging: on (low)
Default: deny (incoming),allow (outgoing),disabled (routed)
New profiles: skip

    To                         Action      From
--                         ------      ----
80/tcp (Nginx HTTP)        ALLOW IN    Anywhere                  
80                         ALLOW IN    Anywhere                  
80/tcp (Nginx HTTP (v6))   ALLOW IN    Anywhere (v6)             
80 (v6)                    ALLOW IN    Anywhere (v6) 

当我用wrk或loadtest(npm)运行负载测试时,一切似乎都运行正常.例如

wrk -t12 -c50 -d5s http://192.168.178.57/getCats/eng

所以本地我可以访问Nginx服务器,但当我尝试使用我的手机(3G / 4G)从公共访问服务器时,我无法访问服务器.究竟我错过了什么?

编辑:我试图通过http://PUBLIC_IP_ADDR/getCats/eng访问该服务,而不是本地地址.

最佳答案
你的Nginx配置看起来非常好.

为了能够从外部访问您的服务器,您需要来自ISP的公共静态IP. ISP也不应阻止到端口80和443的传入流量(如果您决定使用https).

然后你可能有这样的局域网:

ISP <---> Router <---> Server
             ^
             |
             ----> your other devices

在这种情况下,公共IP将分配给路由器,所有其他设备将具有本地专用IP,如192.168.x.x / 24 / 10.x.x.x / 8 / 172.16.0.0 / 20

您需要从路由器配置到服务器的私有IP的端口转发.根据路由器的供应商,此功能可称为虚拟服务器,通常位于WAN配置附近.将其设置为将TCP端口80转发到服务器本地端口80,并将其设置为443.

此外,您可能需要将服务器配置为静态IP,以便本地IP地址不会更改

原文链接:https://www.f2er.com/nginx/434297.html

猜你在找的Nginx相关文章