i am trying to host my dotnet c# web application on ubuntuu server.
So i followed this tutorial from youtube. unfortunately it does not work correctly.
When i open my IP in the browser i get 502 Bad Gateway from nginx.
And my app1.service is not active i guess. i get this output:
I hope you can help me with this. Here is my default.config file /etc/nginx/sites-available/default
server {
listen 80;
server_name example.com *.example.com;
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;
}
}
not sure wether this is correct, i copied from the tutorial above.
This is inside my app1.service file /etc/systemd/system/app1.service
[Unit]
Description= mvcnew webapp
[Service]
WorkingDirectory=/var/www/app1
ExecStart=/usr/bin/dotnet /var/www/app1/MSP.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=mvcnew
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
I am not sure what file i should insert instead of the MSP.dll . I tried different .dll files from my project, but no difference in the output.
I hope you can find the error or help me debugging! thanks!!
nginx is fine i guess
I have checked the video tutorial that you are using for that and it seems to be straightforward and absolutely correct.
Usually, 502 error means that the Nginx service is not able to connect to the backend ( in your case it should be your app on port 5000 ). So the question is, are you sure that your application is indeed using 5000 port? If it is running on a different port, make sure to adjust the Nginx conf with the correct port and restart the Nginx service:
sudo service nginx restart
If you still experience difficulties with that, I recommend signing up for a web hosting provider and using a low-cost plan for dev purposes. They usually can help with any configuration and deployment of your app.