windows服务器如何部署若依前后端分离项目,vue前端?

首先先保证,若依前后端分离项目在本地能正常运行,此处讲解的是Vue前端的项目部署。

部署步骤:

1、先安装nginx服务器

下载地址:https://www.nginx.cn/nginx-download

2、打包若依前端vue项目

打包命令:

npm run build:prod                                                 

       

                 

   打包完成后,我们回看到新生成一个dist文件夹

                             

将dist文件夹放到你要发布的路径文件下,配合nginx.conf配置文件里的路径如下:

                          

3、配置nginx配置文件

解压下载好的nginx压缩包,并进入目录,用notepad++打开文件夹里的nginx.conf配置文件

进行如下配置,可以直接复制


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		#配置本地dist路径
        location / {
            root   F:\TestPackge\dist;
			try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
		#配置后端接口
		location /prod-api/{
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://localhost:8080/;
		}
		# 配置history模式带来的刷新就是404
		
        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

主要是如下修改:

4、启动nginx服务器

先看一下前端Vue的端口配置

启动nginx

启动后端服务

浏览器输入地址:http://localhost:81/  即可访问

   

到此,前端vue就部署成功了。

Windows服务器部署Django框架(如若依 ORM)通常需要经过以下几个步骤: 1. 安装Python和相关环境:首先确保Windows服务器上安装了Python(推荐使用Python 3.x版本),并安装好Visual C++ Build Tools(如果遇到某些依赖库的问题)。可以访问Python官网下载适合的Python版本。 2. 安装Django:在命令行工具(如Git Bash、PowerShell或CMD)中,通过pip安装Django及其依赖包,例如: ``` pip install django ``` 3. 创建项目:使用`django-admin startproject your_project_name`创建一个新的Django项目,并进入项目目录。 4. 配置数据库:Django若依(orm)默认支持SQLite,但生产环境中通常会使用像MySQL、PostgreSQL等其他数据库。修改项目的`settings.py`文件,配置合适的数据库连接参数。 5. 搭建Web服务器:推荐使用像Apache、Nginx或IIS这样的Web服务器,具体取决于公司的需求和管理环境。安装对应的软件,然后配置它们监听Django应用的URLs。 6. 设置静态文件:将项目的静态文件(如CSS、JS和图片)配置到Web服务器的静态文件夹路径中,以便提供给前端。 7. 运行项目:在服务器启动Django应用,这通常通过运行`python manage.py runserver [your_server_address:port]`完成。记得替换地址和端口为你实际的服务器设置。 8. 部署到生产环境:在生产环境中,可能还需要考虑负载均衡、持久化数据存储、SSL加密等因素,以及部署到虚拟主机或云服务提供商(如AWS、Azure或阿里云)。
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值