我在这个问题上完全是菜鸟,但我真的很想部署我的工作。
MERN 堆栈中有一个应用程序。(蒙戈,快递,反应,节点)
我使用 nginx 使用简短指令设置了 ubuntu 上的 VPS 服务器:
https ://github.com/yestellar/deploy-node-nginx-ssl
服务器由Jino 提供。
在根目录中,我有 2 个文件夹:客户端和服务器,我实际上在其中克隆了必要的存储库。在服务器文件夹中,我克隆了节点服务器并启动它,控制台中显示一条消息,说明一切正常。然后,使用 pm2,我使用上面链接中文章中的命令启动了客户端。
NODE_ENV=production pm2 start npm --name strapi -- run start # Запустить в режиме продакшн npm run start скрипт и назвать "strapi"
状态显示“正常”
一般来说,在任何地方,所有状态都可以:nginx、node、npm、mongo……但该站点给出了 404。
我尝试了不同的设置和代理,/etc/nginx/sites-available/default
但它不起作用
怎么修?我将非常感谢任何信息。
这是代码/etc/nginx/sites-available/default
:
PS带有return的行被注释掉了,因为 无休止的重定向,首先您需要至少使 http 工作,然后我将处理 https。
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 site-name.ru www.site-name.ru;
location / {
proxy_pass http://localhost: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;
proxy_redirect off;
}
# 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;
#}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site-name.ru/fullchain.pem; # man>
ssl_certificate_key /etc/letsencrypt/live/site-name.ru/privkey.pem; # m>
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
server {
if ($host = www.site-name.ru) {
# return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = site-name.ru) {
#return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name site-name.ru www.site-name.ru;
return 404; # managed by Certbot
}
问题解决了。我在这里的 nginx 文档中找到了我的问题的答案:http: //nginx.org/ru/docs/beginners_guide.html
正如你在我的文件中看到的
/etc/nginx/sites-available/default
有表格的块
server { ... }
。在每个这样的块中都有一个端口监听器
listen
,以及location
问题是在
server
标准所在的第二个街区,listen 80
没有标明位置。我一标记,服务器就开始发出我的申请