阿里云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服务器、域名为例

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

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

相关推荐
翼龙云_cloud1 小时前
阿里云渠道商:如何手动一键扩缩容ECS实例?
运维·服务器·阿里云·云计算
墨风如雪2 小时前
拒绝被找回!MJJ必修课:Outlook邮箱交易后的“防回手”安全设置全攻略
服务器
DX_水位流量监测3 小时前
大坝安全监测之渗流渗压位移监测设备技术解析
大数据·运维·服务器·网络·人工智能·安全
电商API&Tina3 小时前
京东 API 数据采集接口接入与行业分析
运维·服务器·网络·数据库·django·php
Mr_Xuhhh3 小时前
博客标题:深入理解Shell:从进程控制到自主实现一个微型Shell
linux·运维·服务器
864记忆4 小时前
Qt创建连接注意事项
数据库·qt·nginx
齐 飞5 小时前
使用阿里云的MaxCompute查询sql时报错:DruidPooledPreparedStatement: getMaxFieldSize error
sql·阿里云·odps
m0_738120727 小时前
应急响应——知攻善防靶场Linux-1详细应急过程
linux·运维·服务器·网络·web安全·ssh
GHL2842710907 小时前
无法连接服务端socket
linux·服务器·网络
kylezhao20197 小时前
S7-1200 CPU 与 S7-200 SMART S7通信(S7-1200 作为服务器)
运维·服务器