nginx安装步骤,源码编译安装(源码编译,可以自定制更多功能) openssl

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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 ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 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默认配置

1.解决软件正常运转所需依赖包,

yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y

2.下载源代码

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

3.解压缩

tar -zxvf nginx-1.12..tar.gz

4.进入源码目录,编译安装

./configure --prefix=/opt/nginx112/
make
make install

5.进入nginx安装好的目录

cd /opt/nginx112/

6.学习nginx功能目录,nginx主目录结构如下

[root@s16ds nginx112]# ls
conf 配置文件nginx.conf(nginx的功能参数,都在这个文件定义了)
html 存放前端页面
logs 存放nginx的运行日志,错误日志
sbin 存放nginx可执行程序的目录

9.学习nginx.conf 核心配置

#nginx web核心功能在这里已定义
http {
#定义nginx虚拟主机的
server {
#nginx监听的端口,默认浏览器是80
listen ;
#填写服务器的域名,如果你有域名,nginx会解析到当前这个虚拟主机
#当我访问pythonav.cn:
server_name pythonav.cn; #location就是nginx的路径资源匹配,
#就是当我请求
#pythonav.cn
#pythonav.cn/man.jpg
#pythonav.cn/av/pian.mp4
#这个 location / 这个语法是万能匹配,你所有的请求,都会进入这个location
location / {
#这个root参数,用于定义网页根目录,路径
root html;
#定义网页的首页文件,名字且必须叫做index.html
index index.html index.htm;
} error_page /.html;
} }

10.nginx多虚拟主机

ip 和域名的关系 一对多

在自己的linux服务器上,运行2个网站

nginx.conf定义多虚拟主机配置如下:

http{
#虚拟主机1,我门用它运行,吃鸡网站
server{
listen ;
#当我访问的域名是 s16chiji.com ,就进入这个server标签
server_name s16chiji.com;
location / {
#返回/opt/s16chiji目录下的内容
root /opt/s16chiji/;
index index.html;
}
}
#虚拟主机2,用它运行,s16韩剧网站
server{
listen ;
server_name s16hanju.com;
location / {
root /opt/s16hanju;
index index.html;
}
} }

11.配置两个虚拟主机的网站资源

    .配置吃鸡网游的资料
在/opt/s16chiji 目录下创建index.html .配置韩剧网址
在/opt/s16hanju 目录下创建index.html .配置两个本地解析的域名 ,问题?去linux下还是windows下配置??
在本地 修改C:\Windows\System32\drivers\etc\hosts文件,写入如下配置
192.168.15.71 s16chiji.com
192.168.15.71 s16hanju.com .在windows下测试访问 是否正常
s16chiji.com
s16hanju.com

12.定义nginx错误页面优化 404页面定制
修改nginx.conf ,找到如下参数

#通过这个参数,定义错误页面的文件 ,当状态码是    时,返回40x.html页面
error_page /40x.html;

13.nginx用访问 日志access.log
找到nginx.conf开启如下功能

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;

配置填写完毕后,重启nginx,加载功能

nginx -s reload

centos下Nginx安装和配置多个域名的虚拟主机的更多相关文章

  1. Centos下 Nginx安装与配置

    网上找了好多资料.都很难找全,这里以这个目录为主,进行备注. Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.它最常的用途是提供 ...

  2. centos下nginx安装和配置

    注:此文是根据前辈的博客和自己实际动手总结出来的,不喜勿喷 1.准备工作 Nginx的安装依赖于以下三个包,意思就是在安装Nginx之前首先必须安装一下的三个包,注意安装顺序如下: 1 SSL功能需要 ...

  3. centos下nginx安装与配置

    nginx依赖以下模块: l  gzip模块需要 zlib 库 l  rewrite模块需要 pcre 库 l  ssl 功能需要openssl库 tar xzvf nginx-1.9.15.tar. ...

  4. CentOS 下 redis 安装与配置

    CentOS 下 redis 安装与配置   1.到官网上找到合适版本下载解压安装 [root@java src]# wget -c http://redis.googlecode.com/files ...

  5. centos7系统下nginx安装并配置开机自启动操作

    准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...

  6. Nginx总结(四)基于域名的虚拟主机配置

    前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...

  7. Apache+php+mysql的安装与配置 - 之三(Apache的虚拟主机配置)

    Apache+php+mysql的安装与配置 - 之三(Apache的虚拟主机配置) Apache核心(Core)配置 VirtualHost 语法 <VirtualHost addr[:por ...

  8. 01 - nginx - 安装、配置文件、默认网站、虚拟主机

    一.运维: . 介绍服务器. 服务器逻辑: 服务器选择 操作系统 部署逻辑 业务环境部署逻辑 业务部署图 软件部署文档 日常维护文档 测试 开发上传代码到源码系统 上线 - 测服务器,内测 预发布测试 ...

  9. nginx在CentOs下的安装及配置

    前言: 先介绍一下nginx: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强, ...

随机推荐

  1. cad2018卸载/安装失败/如何彻底卸载清除干净cad2018注册表和文件的方法

    cad2018提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装cad2018失败提示cad2018安装未完成,某些产品无法安装,也有时候想重新安装cad2018 ...

  2. Java内存溢出问题总结

    使用Java那么久,在此总结一下Java中常见的内存溢出问题以及对应的解决思路 堆溢出 报错信息 java.lang.OutOfMemoryError: Java heap space 报错原因 堆中 ...

  3. Dubbo启动时服务检查

    所谓启动时服务检查是指Dubbo在启动的时候会检查当前引用的服务是否可用,不可用会抛出异常,阻止程序的初始化,以便能在上线前快速的找到问题,默认的情况下check=true 通过设置check=fal ...

  4. Fiddler抓包连接失败502的解决方法

    本篇用户记录,在用Fiddler遇到过的坑,首先, 先上图,遇到的问题,提示主机连接失败.只是打开Fiddler,不会报这个问题,只有当Fiddler和火狐浏览器一起启动的时候,才会报这个错. 尝试去 ...

  5. odoo开发 相关知识点

    (1)导入模块可以起别名: (2) 新的模型前端要调用显示有关联的另一个模型的相关字段 (3) 传递上下文 搜索视图打开默认按照接收的参数搜索显示: 发起端视图 上下文写法: 目标端 触发显示,搜索视 ...

  6. MapReduce中的倒排索引

    0.倒排索引资料: http://blog.csdn.net/pzasdq/article/details/51442856 1.三个日志源文件: a.txt hello tom hello jerr ...

  7. java重点知识

    一.java基本知识点 java是由SUN公司在1995年推出的,在2009年SUN公司又被甲骨文公司收购,所以甲骨文公司获得java版权.其底层是由C语言写的,java分为三个体系: JavaSE, ...

  8. 10分钟打造强大的gvim

    感谢Ruchee的共享精神,让我等vim新手省去了配置vim的麻烦(教程地址:配置文件使用指南). 只需要简单的6个步骤,就可以配置完成一个强大的gvim神器,下图是我的最终配置效果图. (另外,我的 ...

  9. Java8-函数复合用法

    JDK8自带的函数式接口Function有两个默认方法andThen和compose,它们都返回Function的一个实例,可以用这两个方法把Function接口所代表的的Lambda表达式复合起来. ...

  10. JAVA框架之Hibernate【配置文件详解】

    Hibernate配置文件主要功能是配置数据库连接和Hibernate运行时所需的各种属性,配置文件应该位于JAVA应用或者JAVA Web应用的类文件中,刚开始接触Hibernate的时候,感觉Hi ...