繁体   English   中英

Node.js App和Nginx的服务器配置

[英]Server Configuration for nodejs App and nginx

我有一个运行App的应用程序运行正常,可以访问根URL。 但是无法访问其他网址。 应用程序是使用nodejs express框架构建的。 我的服务器操作系统是Ubuntu17。我需要在http://35.202.2.217中运行我的应用程序,而不要在其他端口上运行。 那就是为什么我使用代理通行证。 我被困在这里。 我需要做什么

例如, http:// localhost:1336 / pages

我正在使用Nginx。

我的nginx代码

upstream adshackers {
        server 10.128.0.2:8082;
        server 10.128.0.2:9082;
        server 10.128.0.2:3082;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
        root /var/www/html;
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
        server_name adshackers.com;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
        proxy_pass http://adshackers/;
        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;


                try_files $uri $uri/ =404;
        }
        # pass PHP scripts to FastCGI server
        # 
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

因此,我已经对其进行了一些清理,并删除了php部分,除非您还提供了php文件。

upstream adshackers {
           server localhost:1336;
}

server {
       listen 80 default_server;
       listen [::]:80 default_server;

       root /var/www/html;

       server_name adshackers.com;

       location / {
            proxy_pass http://adshackers;
            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正在运行的主机托管在同一台计算机上,并且如示例所示监听localhost:1336

在这种情况下,当一个http请求到达adshackers.com时(如果DNS条目正确),nginx会将请求转移到localhost:1336

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM