阿里云ecs服务器,nginx多域名多项目部署教程,含本地部署教程

nginx多域名部署项目

  • 本地部署
  • 线上部署

一、本地部署

  • 第一步:

win+r 输入drivers



打开hosts文件,编辑

加行

127.0.0.1 自定义域名

...

  • 第二步:

下载 nginx

安装好以后

打开ngin安装目录,选择nginx.conf

打开

yaml 复制代码
#user  Administrator;
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 {
    client_max_body_size 1024m;
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64K;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    
server {
        listen       80;
        server_name  host中配置的自定义域名;
	gzip_static on;
        charset utf-8;
	client_max_body_size 1024m;
 
        location / {
            root   填写你的前端代码目录;#例如:C:\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 后端域名地址 注意:加端口号;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   填写你的前端代码目录;#例如:C:\dist
        }
    }

server {
        listen       80;
        server_name  host中配置的其他自定义域名;
	gzip_static on;
        charset utf-8;
	client_max_body_size 1024m;
	#配置前端地址
        location / {
            root   其他前端项目目录地址;
            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 其他项目后端地址;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   其他前端项目目录地址;
        }
    }


}
yaml 复制代码
nginx常用命令:
start niginx //启动命令
nginx -s stop  //终止nginx
nginx -s reload //重启

二、线上部署

1、以阿里云ecs服务器、域名为例

第一步:先在阿里云后台配置好二级域名

第二步:如"本地部署"。只是将前后端目录地址换成服务器上实际的目录地址,域名地址换成阿里云的,就可以了。

相关推荐
likfishdn14 分钟前
Linux的文件与目录管理
linux·运维·服务器
渲染101专业云渲染15 分钟前
川翔云电脑优势总结
服务器·3d·电脑·blender·maya
chian-ocean33 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=35 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水44 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
橘子味的茶二44 分钟前
高级系统架构师--第十章:计算机网络
服务器·计算机网络·系统架构
紫菜(Nori)1 小时前
短连接服务器压测-wrk
服务器·压力测试
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
浪九天4 小时前
Nginx系列05(负载均衡、动静分离)
nginx·运维开发·持续部署
Tisfy5 小时前
LeetCode 1472.设计浏览器历史记录:一个数组完成模拟,单次操作均O(1)
服务器·leetcode·浏览器·memcached·题解·模拟·数组