如何使用 ngnix 将我的域重定向到 localhost: 3000 [英] how to redirect my domain to localhost: 3000 using ngnix
问题描述
我对这一切都不熟悉.
我将把你放在上下文中.我在 aws 中购买了一个域 miweb.pe
和一个实例.目前我的域重定向到我的 aws 实例,因为我已经在 myweb.pe
中注册了我的 amazon 实例的 dns 服务器.
I'm going to put you in context. I bought a domain miweb.pe
and an instance in aws. Currently my domain redirects to my aws instance because I have registered the dns servers of my amazon instance in myweb.pe
.
我购买了 ssl 证书并尝试将其安装在我的 amazon 实例上,我还安装了 nginx
.我无法向 myweb.pe
重定向到当前在端口 3000 下具有活动的 nodejs 服务的 aws 实例发出任何请求.
I bought an ssl certificate and am trying to install it on my amazon instance, where I also installed nginx
. I am unable to make any request to myweb.pe
redirect to the aws instance that currently has a nodejs service active under port 3000.
这是我当前的配置.我做错了什么?
this is my current configuration. What am I doing wrong?
server {
listen 443;
server_name myweb.pe;
ssl on;
ssl_certificate /etc/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/beekey.key;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 80;
server_name www.myweb.pe;
return 301 https://myweb.pe$request_uri;
}
# Redirige de https://www.tudominio.com a https://tudominio.com
server {
listen 443;
server_name www.miweb.pe;
return 301 $scheme://myweb.pe$request_uri;
}
总而言之,我希望在访问 myweb.pe
时,它实际上访问的是在我的亚马逊实例上运行的localhost: 3000
.
in summary, I want that when accessing myweb.pe
it actually accesses thelocalhost: 3000
which is running on my amazon instance.
推荐答案
那么,你面临的问题是什么,我可以在你的 nginx 规则中看到一个问题,servername 你需要输入域名称而不是本地主机.另一件事是我假设您在端口 3000 上的服务应该已经在运行.
So, what is the issue you are facing, I can see one issue in your nginx rule for servername you need to type domain name and not localhost. The other thing is I am assuming your service on port 3000 should already be running.
这篇关于如何使用 ngnix 将我的域重定向到 localhost: 3000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!