4

我正在尝试配置default.conf/etc/nginx/conf.d显示位于的简单登录页面/home/ubuntu/project-source/company/entry/index.html

据我所知,域设置正确指向服务器

A: test24.company.io -> <aws-elastic-IP>

默认配置:

server {
    listen       80;
    server_name  localhost;

    index index.html;

    location / {
        root   /home/ubuntu/project-source/company/entry;
    }
}

server {
    server_name test24.company.io www.test24.company.io;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test24.company.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test24.company.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = test24.company.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen      80;
    server_name test24.company.io www.test24.company.io;
    return 404; # managed by Certbot
}

sub1附加问题:可以说,该项目将在 2 个子域上运行 2 个进程,sub2并且它们将分别在 localhost:3001和上运行localhost:3002,我如何配置default.conf以指向/代理这些进程?

4

2 回答 2

1

先用这种方式将HTTP重定向到HTTPS

server {
listen 80;
listen [::]:80;
server_name example.com www.example.com; 
return 301 https://example.com$request_uri;
}

其次,您的服务器根目录未包含在 SSL 服务器中,它应该包含

root   /home/ubuntu/project-source/company/entry;

第三您可以在不同的端口上添加您想要的应用程序。只需复制粘贴整个服务器代码并更改所需的值,如根位置和端口

编辑结束后保存并重新启动服务器

sudo service nginx restart
于 2018-08-14T16:51:07.567 回答
0

好吧,经过很多天和几个小时的努力,我得出了这个解决方案:

  1. 在 GoDaddy 的 DNS 上,我添加了这些记录:
    A: test24.company.io -> <aws-elastic-IP>
    A: sub1.test24.company.io -> <aws-elastic-IP>
    A: sub2.test24.company.io -> <aws-elastic-IP>
    注意: 所有 3 条记录都指向同一个弹性 IP,无需为每个子域设置单独的弹性 IP。

  2. nginx conf文件配置如下: https ://gist.github.com/ahmed-abdelazim/b3536c1780afc4215ef57633bbe77a88

这篇文章是关于为服务器上的不同端口设置 nginx 代理的非常有用的指南。

nginx 配置文件中的所有其余部分都是由 certbot 生成的,它还管理从 http 到 https 的重定向。




模组注意事项:由于某种原因,我似乎无法在此答案中格式化 GitHubGist 的代码。

于 2018-08-16T13:32:31.730 回答