簡體   English   中英

nginx 配置(Spring + Angular)

[英]nginx config (Spring + Angular)

我需要有關如何為 nginx 編寫配置的幫助 我想提供一個與Spring API通信的Angular應用程序。 我還沒有將我的文件復制到服務器,所以如果您也可以推薦一個默認位置,那就太好了。

我不知道如何調試它,也不確定它是否會起作用。 這也會加載我的 2 個配置文件嗎? 我需要在主配置中寫一個 server_name 嗎? 我需要在某處寫一個索引指令嗎?

我遵循了一個教程,看到我可以創建 2 個配置文件:
/etc/nginx/sites-available/api.domain.com.conf

server {
        server_name api.domain.com;
        location /domain/api/ {
                proxy_pass http://localhost:8081;
                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;
        }
}

/etc/nginx/sites-available/domain.com.conf;

server {
        server_name domain.mk www.domain.mk;
        location /domain/app/ {
                proxy_pass http://localhost:4200;
                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;
        }
}

這就是我的主要配置文件的樣子(我在/etc/nginx/sites-enabled/[file]中創建了指向上面 2 個文件的符號鏈接):

/etc/nginx/nginx.conf :

error_log       logs/error.log;

events {
        worker_connections 1024;
}

http {
        include /etc/nginx/sites-enabled/*;

        server {
                listen          80;
                access_log      logs/access.log;
        }
}

如果您使用 2 個單獨的文件也沒關系。 但是你需要在你的 index.html 存在的地方配置 root。

 server { server_name api.domain.com; root /path/of/your/ui/dist/folder/; index index.html index.htm; location /domain/api/ { proxy_pass http://localhost:8081; 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; } }

重啟Nginx服務器進行測試。 請在Angular項目環境中配置域名.json文件進行重定向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM