使用 2 个应用的 IP 地址创建测试服务器

Create test server using IP address for 2 apps

我想使用数字海洋水滴部署测试服务器。我已经搞定了,但不知道如何设置可用的 nginx 站点以使其正常工作。我在服务器上有两个应用 运行:

/var/www/html/new_app(应使用端口 8080) /var/www/html/old_app(应使用端口 8081)

我不知道我在这里做什么,并尝试查看示例,但它们都使用域名而不是本地主机或标准 IP 地址。

我目前拥有的:

/etc/nginx/sites-available/default

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

        root /var/www/html/new_app;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}

/etc/nginx/sites-available/old

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

        root /var/www/html/pottstown_old;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass http://localhost:8081/;
        }
}

我尝试为旧站点添加另一个文件,但出现错误:

nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored nginx: [warn] conflicting server name "" on [::]:80, ignored nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

但是当我调出IP地址时,我得到无法打开页面。我如何设置它以将对 64.225.60.54 的请求发送到为新应用程序提供服务的 8080 端口,并将对端口 8081 的请求发送到 old_app?

我只需要一台服务器和两个位置块吗?我只是不明白。

不确定您要托管哪种类型的应用程序,但总的来说。

如果您的应用程序需要两个不同的端口,您应该创建两个服务器块。

A​​pp NEW - 监听 8080

server {
   listen 8080;
   listen [::]:8080;

   root /var/www/html/new_app;
   index index.html index.htm;
}

应用程序旧 - 收听 8081

server {
   listen 8081;
   listen [::]:8081;

   root /var/www/html/old_app;
   index index.html index.htm;
}