如何解决数字海洋上的 NGINX 角度路由
我在 Digital Ocean 上有一个 ubuntu 服务器,我正在服务器上运行一个应用程序。
该应用程序是一个 Angular 10+ 应用程序,通过 IP 地址访问时它可以正常工作:
http://139.59.22.93/ ---> 有效
http://139.59.22.93/dashboard ---> 有效
http://139.59.22.93/register ---> 有效
但是当我尝试通过域名访问它时,它根本没有路由。 http://ebharat-tms.in/ ---> 工作并加载基本网站 http://ebharat-tms.in/dashboard ---> 不起作用。 http://ebharat-tms.in/register ---> 不起作用。
我使用 Nginx 来配置我的网站,我的配置如下所示:
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.Nginx.com/resources/wiki/start/
# https://www.Nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases,administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the Nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications,such as Drupal or wordpress. These applications will be made
# available underneath a path with that package name,such as /drupal8.
#
# Please see /usr/share/doc/Nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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/tms/apps/tms/;
# Add index.PHP to the list if you are using PHP
index index.html index.htm index.Nginx-debian.html;
server_name ebharat-tms.in;
#location / {
# First attempt to serve request as file,then
# as directory,then fall back to displaying a 404.
# try_files $uri $uri/ =404;
#}
location / {
try_files $uri$args $uri$args/ /index.html;
}
location /api {
proxy_pass http://localhost:8080/api;
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;
}
# 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;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
我正在使用 pm2 优雅地管理流程并通过 express server.js 提供我的文件:
"use strict";
const express = require("express");
const compression = require("compression");
const _port = 9000;
const _app_folder = 'dist/apps/tms';
const app = express();
app.use(compression());
// ---- SERVE STATIC FILES ---- //
app.get('*.*',express.static(_app_folder));
// ---- SERVE APLICATION PATHS ---- //
app.all('*',function (req,res) {
res.status(200).sendFile(`/`,{
root: _app_folder
});
});
// ---- START UP THE NODE SERVER ----
app.listen(_port,function () {
console.log("Node Express server for " + app.name + " listening on http://localhost:" + _port);
});
我的 Nginx 配置在 location / 下也有 proxy_pass :
proxy_pass http: //localhost:9000;
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;
我在这里遗漏了什么吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。