【发布时间】:2020-10-12 20:51:14
【问题描述】:
我正在数字海洋上部署我的 react 应用程序。我已按照本教程进行操作,一切顺利:https://www.youtube.com/watch?v=lN0oiYqenpA&ab_channel=RyanMichaelHirst
现在每当我访问我的 ip 或域名时,都会出现以下错误:404 not found.
每当我运行 nginx 的日志时,它都会说正在使用端口 80。因此我运行这个:
sudo netstat -pan | grep ":80"
tcp 0 0 159.203.87.191:80 52.84.150.39:31164 SYN_RECV -
tcp 0 0 159.203.87.191:80 52.84.150.39:38386 SYN_RECV -
我知道,这是一个内部错误,但我似乎找不到那个错误。 我有两件事在同一个端口上运行,一切都崩溃了。它昨天还在工作,我受到了 nginx 页面的欢迎。
这是我的服务器配置。(nginx)
upstream my_nodejs_upstream {
# (this is the server's ip address)
server x.x.x.x.;
keepalive 64;
}
server {
listen 80;
listen [::]:80 ipv6only=on;
# 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.html index.htm index.nginx-debian.html;
server_name mmt-university;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://universitymmt.com/;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_read_timeout 240s;
}
# 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.4-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;
#}
}
【问题讨论】:
-
你的 nginx.conf 被设置为所谓的 reverse proxy 将传入的请求转发到
http://universitymmt.com/哪个服务器运行它?它在哪里?如果它和你的 nginx 服务器是同一个 droplet,那么你就是在告诉 nginx 将你的请求转发给它自己。通常,当您在 nodejs 应用程序前面使用 nginx 时,您会有类似proxy_pass http://localhost:3000;这样的一行, -
Digital Ocean 有很棒的教程。这与您的问题有关。 digitalocean.com/community/tutorials/…
-
@O.Jones 我有一个问题,说我在其他地方托管我的域,并且名称服务器指向我在 digitalocean 使用的那些。我已准备好部署该应用程序。我是否只是按照您在上面粘贴的链接进行操作?谢谢。
标签: node.js reactjs nginx digital-ocean