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

至此,一切大功告成。

相关文章
相关标签/搜索