
Simple Tutorial to publish aspnet core on centos in 5 minute!
1. Install Centos 7 x64 OS.
2. Install .Net on Centos
|
1 2 3 4 5 6 7 8 |
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:
|
1 2 3 4 5 6 |
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
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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:
|
1 2 3 4 5 |
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
|
1 |
/usr/sbin/setsebool -P httpd_can_network_connect 1 |
7. Start Dotnet Application
|
1 |
dotnet /usr/share/nginx/IdentityServer4.API/IdentityServer4.Admin.API.dll |
8. Create service to start/stop Application
|
1 |
/etc/systemd/system/identity.service |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[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
|
1 |
sudo systemctl enable identity |
Start Service
|
1 |
sudo systemctl start identity |
If you want ssl for identity, install free certificate by letsencrypt
|
1 2 |
sudo yum install certbot-nginx sudo certbot --nginx -d identity.ge -d www.identity.ge |
10. Install MysqlServer
|
1 2 3 4 5 6 7 |
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
|
1 |
sudo mysql_secure_installation |
12. Create DB and User
|
1 2 3 |
mysql -u root -p create database testdb; grant all on testdb.* to 'testuser' identified by 'password'; |