Linux系统使用宝塔面板下配置ASP.NET CORE环境 Nginx+mysql

1.登录linux服务器,安装宝塔服务器工具,命令如下(万能安装脚本):

if [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh ed8484bec

2.等待安装完成,期间可能要输入Y确认继续执行;安装完成后最后会出现一个网址和帐号密码;输入网址,登录成功后,安装推荐设置NGINX 1.6,mysql5.7,及其他默认
3.等待安装完成后,安装netcore2.2,命令如下:

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.2

4.安装完成后,新建ftp及mysql上传到线上,然后找到网站文件路径,执行运行操作:

cd /www/wwwroot/gaoyi
dotnet Ctmon.Web.dll

5.运行完后新建执行持续执行工具,步骤如下:
5.1创建服务

vi /etc/systemd/system/gaoyi.service

5.2写入文件(下面<>部分是需要变更的)

[Unit]
Description=Web API Application running on CentOS

[Service]
WorkingDirectory= /www/wwwroot/gaoyi
ExecStart=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=gaoyi
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

//<>内的内容按所部署位置编写
WorkingDirectory = /www/wwwroot/gaoyi //程序所在目录
ExecStar=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll //程序运行DLL
SyslogIdentifier = gaoyi

5.3启动服务

systemctl start website

6.执行完上面后,需要到宝塔修改配置
在这里插入图片描述
配置文件内容(proxy_pass http:端口号不可重复)

server {
listen 80;
server_nane gaoyi.ctmon.cn;
index index.php index.html index.htm default.php default.htm default.html
    location / {
        proxy_pass http://localhost:5005;
        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;
    }
}

7.保存后,需要重启nginx
在这里插入图片描述

到此网址配置完成
(以上就完成了,但下面会出现一种情况,就是我们修改文件后,需要上传dll到线上,所以需要执行以下步骤)
1.上传对应的dll
2.上传后需要执行以下命令

systemctl stop gaoyi

3.找到对应的网站文件路径,执行运行操作:

cd /www/wwwroot/gaoyi
dotnet Ctmon.Web.dll

4.执行完后需要执行以下命令

systemctl start gaoyi
systemctl enable gaoyi.service #开机运行服务

注释
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop qihang.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

服务器配置常用端口
80:HTTP端口
443:HTTPS端口
21:FTP端口
465:SMTP邮件发送端口
587:个人QQ邮箱发送端口
1433:SQLSERVER数据库端口
3306: MYSQL数据库端口
8888: 宝塔默认端口

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置 PHP 环境NginxMySQL 和 Redis,你按照以下步骤进行操作: 1. 首,安装 Docker 和 Docker Compose(如果尚未安)。 2. 创建一个新的目录,用于存放你的文件和配置文件。 在该目录下一个 `docker-compose.yml` 文件将以下内容复制到文件中: yaml version: '3' services: nginx: image: nginx:latest : - 80:80 volumes - ./nginx.conf://nginx/nginx.conf ./public:/var/www/html depends_on: - php php: image: php:latest volumes: - ./php.ini:/usr/local/etc/php/php.ini - ./public:/var/www/html mysql: image: mysql:latest ports: - 3306:3306 environment: - MYSQL_ROOT_PASSWORD=your_mysql_root_password - MYSQL_DATABASE=your_mysql_database - MYSQL_USER=your_mysql_user - MYSQL_PASSWORD=your_mysql_password volumes: - ./mysql:/var/lib/mysql redis: image: redis:latest ports: - 6379:6379 volumes: - ./redis:/data ``` 4. 创建一个 `nginx.conf` 文件,并将以下内容复制到文件中。你可以根据需要进行修改。 ```nginx events {} http { server { listen 80; server_name localhost; root /var/www/html; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 5. 创建一个 `php.ini` 文件,并根据需要进行修改。 6. 创建一个 `public` 文件夹用于存放你的 PHP 项目文件。 7. 运行以下命令启动 Docker 容器: ```shell docker-compose up -d ``` 这将会启动 Nginx、PHP、MySQL 和 Redis 容器。 现在,你已经成功配置了 PHP 环境NginxMySQL 和 Redis。你可以将你的 PHP 项目文件放在 `public` 文件夹中,然后通过访问 `http://localhost` 来访问你的应用程序。请确保修改 `mysql` 服务中的环境变量,设置你自己的 MySQL 根密码、数据库名称、用户名和密码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值