百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

nginx配置多个站点使用同一端口

off999 2025-01-08 16:28 10 浏览 0 评论

场景描述

用户在同一台服务器上部署了多个站点,需要使用不同域名的80端口来访问不同的网站

准备事项

  • 主机已安装好nginx服务
  • 站点文件已上传到主机目录
  • 不同域名已解析到主机IP

部署步骤

1、检查/etc/nginx/nginx.conf <span style="color:red">(nginx默认配置文件路径,如果使用其他方式部署,对应部署的其他路径)</span>配置文件,确保文件中包含 include /etc/nginx/conf.d/*.conf;

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;  #nginx站点配置文件路径

    server {
        listen       80 default_server; #默认监听端口
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html; #默认站点路径

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

2、在目录/etc/nginx/conf.d下面新建website1.conf,website2.conf,文件名可自定义。监听端口都改为80端口并绑定不同的域名,root路径分别配置为不同的站点路径。 website1.conf文件内容:

server {
    listen       80;	#website1监听端口
    server_name  one.example.com;	#website1绑定域名
    root         /var/www/html/web1/;	#website1站点路径
    # Load configuration files for the default server block.

    location / {
        index index.php index.html index.htm;	#站点默认页面
        }
    error_page 404 /404.html;
        location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

website2.conf文件内容:

server {
    listen       80;	#website2监听端口
    server_name  two.example.com;	#website2绑定域名
    root         /var/www/html/web2/;	#website2站点路径
    # Load configuration files for the default server block.

    location / {
        index index.php index.html index.htm;	#站点默认页面
        }
    error_page 404 /404.html;
        location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

3、重启nginx服务,验证不同域名访问效果

相关推荐

Python如何操作Excel,xlrd和xlwt类库的使用

xlrd和xlwt类库简介xlrd和xlwt是Python中两个用于处理Excel文件的类库。xlrd用于读取Excel文件,xlwt用于写入Excel文件。这两个类库可以在Python中方便地处理E...

操作Excel,Python根本打不过VBA

很开心今天把一个与财务有关的Excel取数计算方面的项目收尾了。这次项目使用的是ExcelVBA语言开发。作为一名Python语言使用者,经历过这次项目开发后,更加坚定了Python根本不可能动摇V...

个人用户将Excel接入DeepSeek的详细步骤指南

个人用户将Excel接入DeepSeek的详细步骤指南,无需复杂编程基础,提供多种实现方式:一、准备工作:获取DeepSeekAPI密钥1.注册DeepSeek账号-访问[DeepSeek官网...

Python通过win32库操控Excel实战指南

Python通过win32库操控Excel实战指南。同学们,我是张老师。今天给大家讲的是Python通过win32库操控Excel实战指南。今天课的主要内容有:易开发、环境配置、二Excel基础操作实...

如何在Excel中直接使用DeepSeek的功能

在Excel中直接使用DeepSeek的功能(如AI模型能力),目前需通过间接集成方式实现,因为DeepSeek并未提供官方的Excel插件。以下是两种常用方法:方法1:通过API调用集成(推荐)若D...

Python自动化:xlrd读取excel

#pipinstallxlrd工作簿、工作表相关操作:importxlrd#打开工作簿people=xlrd.open_workbook('people1.xls')...

Python自动化:openpyxl读取excel,补充了些内容

打开工作簿,选择工作表importopenpyxl#打开已有工作簿wb=openpyxl.load_workbook('example1.xlsx')#sheetna...

Python自动化:openpyxl读取excel

#pipinstallopenpyxl工作簿、工作表相关操作:importopenpyxl#打开已有工作簿wb=openpyxl.load_workbook('example...

Java的优势:跨平台只是一部分

以下讨论只针对PC端和移动端。Java最大的优势真的在于跨平台吗?以前是,但现在已经不是了。有跨平台需求的仅仅是客户端应用,而不是服务端。例如桌面应用,你的客户可能是Windows用户,也可能是Lin...

都2023年了,为什么大家还都在吹捧 Python?

2023年,Python还可学吗?答案当然是可。近些年间,Python的火热有目共睹,作为一种功能强大的高级编程语言,在2018年的时候它的流行程度就得到了大幅提高。入门人工智能有很多种选择...

Python编程语言的优势有哪些?

1.简单易学:Python采用极简主义设计思想,语法简单优雅,不需要很复杂的代码和逻辑,即可实现强大的功能。这使得Python很适合初学者学习,可以帮助初学者快速入门。2.开源免费:Python所有内...

Python操作Excel库xlrd与xlwt常用操作详解

来源:早起Python作者:刘早起大家好,我是早起。在之前的Python办公自动化系列文章中,我们已经相信介绍了openyxl、xlsxwriter等Python操作Excel库。openpyxl操作...

python处理Excel,从此爱上python

python能干的事情太多,对于小白来说,只能望洋生叹,不过不要灰心,看看我是如何使用python处理Excel的,你就能理解python的简单和高效。一、Excel文件1、文件路径F:/...

软件测试|Python操作Excel制作报表,不要太方便

前言今天我们介绍的是Python操作Excel制作报表,我们需要用到的库是openpyxl,我们主要使用的功能有下列几个功能插入与查询数据分类数据统计数据可视化字体颜色修改基本操作表格初始数据如下图所...

python笔记52:python操作excel

主要内容:小目标:掌握excel模块主要内容:excel相关模块,openpyxl安装使用如果看完这篇文章,你还是弄不明excel相关操作;你来找我,我保证不打你,我给你发100的大红包。1.ex...

取消回复欢迎 发表评论: