Simple Tutorial to publish aspnet core on centos in 5 minute!
1. Install Centos 7 x64 OS.
2. Install .Net on Centos
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo' sudo yum update sudo yum install libunwind libicu sudo yum install dotnet-sdk-2.1.4 sudo yum install dotnet-sdk-2.2 sudo yum install dotnet-sdk-3.1 export PATH=$PATH:$HOME/dotnet
3. Install NGinx
Create Folders:
sudo mkdir -p /etc/nginx/sites-available/ sudo mkdir -p /etc/nginx/sites-enabled #####Create Project Folder####### sudo mkdir -p /var/www/carshistories.com/public_html restorecon -r /var/www/carshistories.com/public_html #Resolved Permission Problem
4. Add Virtual Hosts Config
server { listen 80; server_name identityapi.ge www.identityapi.ge; location / { proxy_pass http://127.0.0.1:5003/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; } }
5. Create Shortcuts
Find in /etc/nginx/nginx.conf:
include /etc/nginx/sites-enabled/*; If not exist add after include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; sudo ln -s /etc/nginx/sites-available/emarket.ge.conf /etc/nginx/sites-enabled/emarket.ge.conf
6. Start Resolving VirtualHosts as Reverse Proxy
/usr/sbin/setsebool -P httpd_can_network_connect 1
7. Start Dotnet Application
dotnet /usr/share/nginx/IdentityServer4.API/IdentityServer4.Admin.API.dll
8. Create service to start/stop Application
/etc/systemd/system/identity.service
[Unit] Description=IdentityWeb [Service] WorkingDirectory=/usr/share/nginx/IdentityServer4 ExecStart=/usr/share/nginx/IdentityServer4/IdentityServer4.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-example User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
9. Enable and start service
sudo systemctl enable identity
Start Service
sudo systemctl start identity
If you want ssl for identity, install free certificate by letsencrypt
sudo yum install certbot-nginx sudo certbot --nginx -d identity.ge -d www.identity.ge
10. Install MysqlServer
yum install wget wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm sudo yum install mysql-server or sudo yum install mariadb-server sudo systemctl start mysqld
11. MysqlServer Configuration
sudo mysql_secure_installation
12. Create DB and User
mysql -u root -p create database testdb; grant all on testdb.* to 'testuser' identified by 'password';