首页 > 其他分享 >.net项目使用Docker部署(包括解决后台验证码,部署后不显示的问题)

.net项目使用Docker部署(包括解决后台验证码,部署后不显示的问题)

时间:2024-08-02 17:16:43浏览次数:11  
标签:index http log 部署 nginx html conf net Docker

Vue部署到Docker

参考文档:手把手教你用 Docker 部署 Vue3 项目_docker部署vue3项目-CSDN博客

参考文档:dockerfile 部署前端vue项目_vue dockerfile-CSDN博客

nginx文档:使用docker安装nginx - 静以修身俭以养德 - 博客园 (cnblogs.com)

结合使用了两个文档的方法和DockerFIle

区别

第一篇使用的是删除nginx默认的 default.conf配置文件然后通过DockerFile进行替换

server {
    listen       80;
    server_name  localhost; # 修改为docker服务宿主机的ip
 
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }
 
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

DockerFile

FROM nginx:该镜像是基于nginx:latest镜像构建的
 
MAINTAINER onesummer:添加说明
 
RUN rm /etc/nginx/conf.d/default.conf:删除目录下的default.conf文件
 
ADD default.conf /etc/nginx/conf.d/:将default.conf复制到/etc/nginx/conf.d/下,用本地的default.conf配置来替换nginx镜像里的默认配置
 
COPY dist/ /usr/share/nginx/html/:将项目根目录下dist文件夹(构建之后才会生成)下的所有文件复制到镜像/usr/share/nginx/html/目录下

第二篇是通过替换nginx默认的nginx.conf使用DockerFIle进行替换

同时需要去创建三个文件夹,然后去替换默认的index

image-20240715010700670

 //nginx.conf文件
user  nginx;
worker_processes  auto;
 
error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /var/log/nginx/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    #gzip  on;
 
  
    server {
        listen       80;
        listen  [::]:80;
		client_max_body_size 20m; 
         client_body_buffer_size 1m;
        #access_log  /var/log/nginx/host.access.log  main;
 
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
 
        #生产环境接口反向代理配置
        location /stage-api/ {
            #保留代理之前的host 包含客户端真实的域名和端口号
            proxy_set_header    Host  $http_host;
            #保留代理之前的真实客户端ip
            proxy_set_header    X-Real-IP  $remote_addr;
            #这个Header和X-Real-IP类似,但它在多级代理时会包含真实客户端及中间每个代理服务器的IP
            proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
            #表示客户端真实的协议(http还是https)
            proxy_set_header X-Forwarded-Proto $scheme;
 
            #写后端服务端口
            proxy_pass http://192.168.1.164:29097/;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
 
    }
 
}

Docker

FROM nginx
 
# 作者信息
MAINTAINER lxp
 
# 挂载目录
VOLUME /usr/share/nginx/html
 
# 复制conf文件到路径
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
 
# 复制html文件到路径
COPY ./html /usr/share/nginx/html

结合

因为我是修改nginx.conf文件同时,并且不想要去创建额外的文件夹所以我就使用了两者结合的方法

image-20240715011323723

Dockerfile

FROM nginx
 
MAINTAINER onesummer
 
RUN rm /etc/nginx/nginx.conf  //删除默认的nginx.conf
 
ADD nginx.conf /etc/nginx/   //添加nginx.conf
 
COPY dist/ /usr/share/nginx/html/

因为我们使用的Element-admin所以需要对nginx.conf做出一定的修改,参照第二篇进行修改

vue3-element-admin:

标签:index,http,log,部署,nginx,html,conf,net,Docker
From: https://www.cnblogs.com/zhaoshiyi/p/18339201

相关文章

  • Asp.Net Core 3.1 每次请求记录接口访问日志
    1publicclassRequestResponseLoggingMiddleware2{3privatereadonlyRequestDelegate_next;4privateRequestResponseLog_logInfo;56publicRequestResponseLoggingMiddleware(RequestDelegatenext)7{8_next=next;9......
  • 在Linux上创建一个.NET Core应用作为服务运行
    要在Linux上创建一个.NETCore应用作为服务运行,你可以使用systemd来管理你的服务。以下是创建服务的基本步骤和示例代码:确保你的.NETCore应用已经发布并且可以在Linux上运行。创建一个新的systemd服务文件。创建一个名为yourapp.service的文件,替换yourapp为你的应用......
  • Ubuntu 部署
    部署.NETCore程序到Ubuntu安装.NETCoreSDK:首先,你需要在Ubuntu上安装.NETCoreSDK。以下是具体步骤:打开终端并运行以下命令,将Microsoft包签名密钥添加到受信任密钥列表,并添加包存储库:wgethttps://packages.microsoft.com/config/ubuntu/20.04/packages-micro......
  • .net 8 应用在docker容器中创建失败 Failed to create CoreCLR, HRESULT: 0x80070008
    在UAT环境中docker容器里部署.net8应用没问题,在dev环境dockerrun启动失败,并报错FailedtocreateCoreCLR,HRESULT:0x80070008以下文章解决了我遇到的问题,感谢https://www.cnblogs.com/cyq1162/p/17981333处理办法增加--security-optseccomp=unconfineddockerrun-......
  • 靠谱的抖音短视频 SEO 矩阵系统源码开发部署----搭建流程分享
    一、需求分析在开始抖音短视频SEO矩阵系统源码的开发部署之前,首先需要明确您的业务需求和目标。例如,您希望系统具备哪些功能,是侧重于关键词优化、内容推荐还是用户行为分析等。同时,还需要考虑系统的可扩展性、稳定性以及与抖音平台的兼容性。通过多平台账号绑定、多任务创......
  • Ceph 的部署
    Ceph的部署过程较为复杂,需要一系列的准备和配置步骤。首先,要进行环境准备,包括关闭selinux和防火墙,设置时间同步,修改主机名和host,配置yum源,创建普通用户,设置静态域名解析等。例如,在环境准备中,可能需要执行如下命令:systemctlstopfirewalld、systemctldisablefirewal......
  • net core 获了取post数据流
    1、可以实例化的通过参数获取[HttpPost]publicIActionResultPost([FromBody]MyModelmodel){//在这里你可以使用model中的数据returnOk(model);}当你发送一个POST请求到这个控制器动作时,ASP.NETCore将自动将请求体中的JSON数据绑定到M......
  • centos7 解决docker 拉取镜像错误 error pulling image configuration: download fai
    为什么会出现i/otimeout错误?i/otimeout错误主要是由于网络连接不稳定或者服务器响应慢导致的。当Docker尝试从镜像仓库拉取镜像时,如果在规定时间内没有得到响应,就会出现i/otimeout错误。“错误的根源在于网络连接和镜像仓库的响应速度” 解决方案:换源为了解决这个......
  • Jenkins 配置 docker 容器
    Jenkins配置docker容器 搭建时打开代理。  1. 搭建dockerpulljenkins/jenkinsdockerrun-d-p10004:8080-p10005:50000-vD:\DockerVolume\jenkins\jenkins_mount:/var/jenkins_home-v/etc/localtime:/etc/localtime--restart=always--namejenkinsj......
  • Jenkins+Jmeter部署性能测试平台
    安装部署Jenkins现在网上信息很多本次不再赘述安装Jmeter本次也不做赘述,另外搜资料吧Jmeter脚本设置Jenkins设置1.安装插件performance,buildwithparameter2.新建项目里配置勾建方式勾建步骤cd/home/jmeterWorkplace/performancetesting/script/home/app/apache......