Nginx静态网站的部署
静态网站的部署
首先先看一下nginx/conf/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 端口, server_name 主机名称, location-root 网站根目录,location-index 网站默认页面
server {
listen 80;
server_name localhost; #charset koi9-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #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;
#}
} #我们以后自己配置虚拟主机的话 就在这个地方新添加server即可 # 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;
# }
#} }
nginx.conf
所以我们部署静态网站,把静态的html页面相关放到html这个目录下即可,当然也可以自己定义目录,修改配置文件即可
那么如果我们想在一个nginx上部署多个网站(不同端口),应该怎么做呢?
配置虚拟主机
虚拟主机,也叫“网站空间”,就是把一台运行在互联网上的物理服务器划分成多个“虚拟”服务器。虚拟主机技术极大的促进了网络技术的应用和普及。同时虚拟主机的租用服务也成了网络时代的一种新型经济形式。
一、端口绑定(以web1,web2两个网站为例)
1,将网站web1(web1网站的所有静态文件,比如web001.html),web2,分别上传到/usr/local/nginx/web1和/usr/local/nginx/web2下
2,修改nginx/conf/nginx.conf 配置文件:(添加两个server信息)
server {
listen 81;
server_name localhost;
location / {
root web1;
index web001.html;
}
}
server {
listen 82;
server_name localhost;
location / {
root web2;
index web002.html;
}
}
3,重启nginx
./nginx -s reload
4,用浏览器访问ip+port

二、域名绑定
我们上面部署的静态网站目前只能通过ip+port访问,那么如果想通过域名访问呢?
答案很简单,只需要修改我们刚才添加到配置文件中的server信息中的server_name:
server {
listen 80;
server_name web1.zy.com;
location / {
root web1;
index web001.html;
}
}
server {
listen 80;
server_name web2.zy.com;
location / {
root web2;
index web002.html;
}
}
前提是你需要有这个域名,并将这个域名指向了这个ip。
Nginx静态网站的部署的更多相关文章
- 【URLOS应用开发基础】10分钟制作一个nginx静态网站环境应用
URLOS开发者功能已上线有一段时间了,目前通过部分开发者的使用体验来看,不得不说URLOS在服务器软件开发效率方面确实有着得天独厚的优势,凭借docker容器技术与其良好的应用生态环境,URLOS必 ...
- nginx 静态网站配置
/************************************************************************************** * nginx 静态网站 ...
- 腾讯云,搭建nginx静态网站服务器
搭建Http静态服务器环境 任务时间:15min ~ 30min 搭建静态网站,首先需要部署环境.下面的步骤,将告诉大家如何在服务器上通过 Nginx 部署 HTTP 静态服务. 安装 Nginx 在 ...
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(一)--技术流ken
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)--技术流ken>,<Ansible常用模块介绍及使用(二)--技术流ken><Ansible剧本介绍及 ...
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(4)
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)–技术流ken>,<Ansible常用模块介绍及使用(二)–技术流ken><Ansible剧本介绍及使用 ...
- nginx静态资源分离部署
修改nginx.conf文件,用于nginx处理静态资源. 主要配置如下(在server配置中加入location配置即可): server { listen 80; server_name 123. ...
- 基于CentOS搭建Nginx 静态网站
系统要求: CentOS 7.2 64 位操作系统 一. 安装 Nginx(在 CentOS 上,可直接使用 yum 来安装 Nginx) yum install nginx -y 安装完成后,使用 ...
- 云服务器搭建 Nginx 静态网站
第一步:安装 Nginx 在 CentOS 上,可直接使用 yum 来安装 Nginx(当然也可以通过下载压缩包.解压.编译的方式安装,不过太麻烦了) yum install nginx -y 第二步 ...
- 搭建 Nginx 静态网站
示例代码:/etc/nginx/nginx.conf user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid / ...
随机推荐
- HTML的后缀显示、标准格式和标签(1)
后缀的显示 win10:打开我的计算机--->点击上面的查看--->选中文件扩展名 win8:打开我的计算机--->点击上面的组织选中文件夹选项--->点击上面的查看---&g ...
- Http权威指南(概述篇总结)
之前的<锋利的jQuery>后面陆续翻完了,实在觉得没什么值得记录的,也就没继续写了,然后看见书架上有 本去年买的<Http权威指南>,其实做web编程的,对于Http协议还是 ...
- Arcgis for Androd API开发系列教程(一)——地图显示与GPS定位
序:最近呢,工作鸭梨不是怎么大,对于自己爱折腾的想法又冒出了水面,开始自己的android开发的学习之旅.但是呢,本人是做GIS的,所以呢,就打算从这方面入手看看,是不是有什么比较好玩的玩意呢,这才导 ...
- ESLint在vue中的使用
ESLint的用途 1.审查代码是否符合编码规范和统一的代码风格: 2.审查代码是否存在语法错误: 中文网地址 http://eslint.cn/ 使用VSCode编译器在Vue项目中的使用 在初始 ...
- NOIP模拟题 友好国度
题目大意 给定一棵树,每个点有点权,求有多少组点对满足两点简单路径上的所有点点权的$gcd=1$. $n,val_i\leq 10^5$ 题解 考虑设$G_i$表示简单路径上所有点点权均为$i$的倍数 ...
- Storm开发过程中的问题与建议
转自:http://blog.csdn.net/ouyang111222/article/details/50061305 (一) topology层级建议设不要设置过多 storm讲究是流式计算,s ...
- SQL Server临时表的使用方案
文章来源:http://www.codesky.net/article/201007/145241.html 我们今天是要和大家一起讨论的是SQL Server临时表的实用大全,如果你对SQL S ...
- 利用DAC(Data-tier Application)实现数据库结构迁移
从一个存在的库,抽取其表结构,对象,权限等,再部署成一个不包含数据的"空库"的方法有很多种.如自带的Generate Scripts功能,自定义脚本提取创建脚本等. 在实际使用中, ...
- YY一下十年后的自己(转)
每到年底总是我最焦虑的时候,年龄越大情况越明显.可能越长大越是对 时光的流逝 更有感触,有感触之后就会胡思乱想.所以随手开始写下这篇文章. 人无远虑必有近忧.那么同学呀,你听说过安利么. 一直都有做总 ...
- 解决Iframe session过期,登录界面无法全页刷新
在登录界面增加如下js代码: <script language=”JavaScript”> if (window != top) top.location.href = location. ...