CENTOS7.3 64位架設使用MYSQL數據庫的ASP.NET CORE網站

注:本人使用的是雲服務器,具體CentOS怎麼安裝這裏不做贅述。javascript

網站架設效果能夠查看https://www.resape.comcss

1、在CentOS上安裝Dotnet Core環境

一、Add the dotnet product feed

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'

二、Install the .NET SDK

sudo yum update sudo yum install libunwind libicu sudo yum install dotnet-sdk-2.1.4

具體介紹可參考以下地址:html

https://www.microsoft.com/net/learn/get-started/linuxcentosjava

2、使用 Apache 在 Linux 上託管 ASP.NET Core

一、安裝 Apache web 服務器

sudo yum -y install httpd mod_ssl

二、配置 Apache 用於反向代理

在/etc/httpd/conf.d/路徑下建立resape.conf,內容以下:mysql

<VirtualHost *:80> ProxyPreserveHost On ProxyPass / http://127.0.0.1:5000/ ProxyPassReverse / http://127.0.0.1:5000/ ErrorLog /var/log/httpd/resape-error.log CustomLog /var/log/httpd/resape-access.log common </VirtualHost>

三、將文件保存與測試配置

sudo service httpd configtest

四、從新啓動 Apache:

sudo systemctl restart httpd
sudo systemctl enable httpd

五、將站點配置爲服務啓動

在/etc/systemd/system/路徑下建立kestrel-resape.service,內容以下:linux

[Unit] Description=Example .NET Web API App running on CentOS 7  [Service] WorkingDirectory=/var/www/html ExecStart=/usr/share/dotnet/dotnet /var/www/html/Resape.dll Restart=always # Restart service after 10 seconds if dotnet service crashes RestartSec=10 SyslogIdentifier=dotnet-example User=apache Environment=ASPNETCORE_ENVIRONMENT=Production  [Install] WantedBy=multi-user.target

六、保存並啓用服務

systemctl enable kestrel-resape.service systemctl start kestrel-resape.service systemctl status kestrel-resape.service

七、查看日誌

sudo journalctl -fu kestrel-resape.service

具體介紹可參考以下地址:nginx

https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/linux-apacheweb

若是一切正常,到目前爲止,網站已經能夠訪問了。sql

3、安裝MariaDB

一、安裝

yum install mariadb-server mariadb 

二、開機啓動

systemctl start mariadb systemctl enable mariadb 

三、初始化

/usr/bin/mysql_secure_installation 

四、開啓遠程訪問權限

use mysql; GRANT ALL PRIVILEGES ON *.* to 'root'@'%' identified by '123456'; flush privileges; 

4、開啓防火牆

一、啓用防火牆

systemctl start firewalld.service

二、開放相應端口

sudo firewall-cmd --add-port=80/tcp --permanent sudo firewall-cmd --add-port=443/tcp --permanent firewall-cmd --permanent --zone=public --add-port=3306/tcp firewall-cmd --permanent --zone=public --add-port=3306/udp

三、從新加載防火牆

sudo firewall-cmd --reload

5、配置SSL證書

一、修改配置文件

將以前的resape.conf修改成以下內容:apache

<VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L] </VirtualHost> <VirtualHost *:443> ProxyPreserveHost On ProxyPass / http://127.0.0.1:5000/ ProxyPassReverse / http://127.0.0.1:5000/ ErrorLog /var/log/httpd/resape-error.log CustomLog /var/log/httpd/resape-access.log common SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:!RC4+RSA:+HIGH:+MEDIUM:!LOW:!RC4 SSLCertificateFile /etc/pki/tls/certs/resape.crt SSLCertificateKeyFile /etc/pki/tls/private/resape.key SSLCertificateChainFile /etc/pki/tls/certs/1_root_bundle.crt </VirtualHost>

注意把證書放入配置文件指定的位置。

二、保存配置文件並重啓Apache

sudo service httpd configtest sudo systemctl restart httpd

至此,一切大功告成。

相關文章
相關標籤/搜索