-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.txt
207 lines (152 loc) · 5.87 KB
/
server.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Oppsett og konfigurering av .Net og Angular på Ubuntu 18.04 server
Ting markert med <forklaring> er plassholdere og må byttes ut med det som gjelder for den gitte VM.
Tilgang til server fra powershell
ssh <brukernavn>@<ip-adresse>
Installering av .Net SDK 5[1]
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-5.0
Installering av Nginx[1]
sudo apt update
sudo apt install nginx
Sjekk status Nginx[1]
sudo systemctl status nginx
Opprettelse av filstruktur
sudo mkdir /var/www
sudo mkdir /var/www/ModernaMedia
sudo mkdir /var/www/ModernaMedia/Angular
sudo mkdir /var/www/ModernaMedia/DotNet
Gi bruker og nginx rettigheter til filstruktur
sudo chown -R <brukernavn>:www-data /var/www
Overfør .Net og Angular filene til servern (f.eks via sftp på Filezilla)
Konfigurer Nginx opp mot Angular[2]
sudo nano /etc/nginx/conf.d/ModernaMedia.conf
Fyll inn det som står under (dette er kun minimum for at angular skal fungere, må supleres)[2]
server {
listen 0.0.0.0:80;
root /var/www/ModernaMedia/Angular;
location / {
try_files $uri $uri/ /index.html;
}
} }
Endre default Konfigen til Nginx så det kun er Angular som lytter på port 80
sudo nano /etc/nginx/sites-available/default
server {
listen 81 default_server; #Alle andre porter enn de(n) som brukes av angular er ok listen [::]:81 default_server;
Sjekk at det ikke er noen feil i konfig filene
sudo nginx -t
Opprett en service som gjør at .Net serveren starter opp automatisk[1]
sudo nano /etc/systemd/system/ModernaMedia.service
Fyll inn dette[1]
[Unit]
Description=ModernaMedia Net5 service
[Service]
WorkingDirectory=/var/www/ModernaMedia/DotNet
ExecStart=/usr/bin/dotnet/var/www/ModernaMedia/DotNet/ModernaMediaDotNet.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=ModernaMedia-dotnet
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Registrer servicen[1]
sudo systemctl enable ModernaMedia.service
Start og kontroller at servicen kjører[1]
sudo systemctl start ModernaMedia.service
sudo systemctl status ModernaMedia.service
sudo systemctl restart ModernaMedia.service
curl -I -X GET localhost:5000/api/weatherforecast/get
curl GET http://139.162.201.189:5000/api/weatherforecast/get
curl GET http://139.162.201.189/api/weatherforecast/get
curl GET localhost:5000/api/weatherforecast/get
curl GET localhost:5000/api/test/get
curl GET http://localhost:5000/api/weatherforecast/get
sudo service nginx restart
etc/nginx/sites-enabled/default
server {
listen 81;
server_name api.modernamedia.no;
root /var/www/ModernaMedia/DotNet;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
etc/nginx/sites-available/default
server {
listen 81;
server_name api.modernamedia.no;
root /var/www/ModernaMedia/DotNet;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo nano /etc/nginx/conf.d/ModernaMedia.conf
#server {
# listen 0.0.0.0:80;
# server_name ModernaMedia.no;
# root /var/www/ModernaMedia/Angular/dist/ModernaMediaAngular/browser;
# location / {
# try_files $uri $uri @backend /index.html $uri $uri/;
# }
# location @backend {
# proxy_pass http://your_upstream_config;
# proxy_pass http://139.162.201.189:4000;
# proxy_pass http://localhost:4000;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $http_host;
# proxy_http_version 1.1;
# proxy_set_header X-NginX-Proxy true;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_cache_bypass $http_upgrade;
# proxy_redirect off;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
#}
#server {
# listen 80;
# server_name www.modernamedia.no # <-- modify here
# return 301 https://$server_name$request_uri?;
#}
#################
server {
listen 80;
server_name modernamedia.no;
location / {
proxy_pass http://localhost:4000;
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;
}
}
PM2
-----------------------------------------
cd /var/www/ModernaMedia/Angular
pm2 start "node dist/ModernaMediaAngular/server/main.js" --name "ModernaMedia"
Referanser:
Hidayat Arghandabi “Ubuntu Servers and ASP.net Core Project Deployment using Nginx” lest 01.03.2021 https://medium.com/faun/ubuntu-servers-and-asp-net-core-project-deployment-using-nginx-d9a3a1f6ac82
NanoDano “Deploy Angular Apps with Nginx” lest 01.03.2021 https://www.devdungeon.com/content/deploy-angular-apps-nginx