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

  1. #user nobody;
  2. worker_processes ;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9.  
  10. events {
  11. worker_connections ;
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17.  
  18. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. # '$status $body_bytes_sent "$http_referer" '
  20. # '"$http_user_agent" "$http_x_forwarded_for"';
  21.  
  22. #access_log logs/access.log main;
  23.  
  24. sendfile on;
  25. #tcp_nopush on;
  26.  
  27. #keepalive_timeout ;
  28. keepalive_timeout ;
  29.  
  30. #gzip on;
  31.  
  32. server {
  33. listen ;
  34. server_name localhost;
  35.  
  36. #charset koi8-r;
  37.  
  38. #access_log logs/host.access.log main;
  39.  
  40. location / {
  41. root html;
  42. index index.html index.htm;
  43. }
  44.  
  45. #error_page /.html;
  46.  
  47. # redirect server error pages to the static page /50x.html
  48. #
  49. error_page /50x.html;
  50. location = /50x.html {
  51. root html;
  52. }
  53.  
  54. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  55. #
  56. #location ~ \.php$ {
  57. # proxy_pass http://127.0.0.1;
  58. #}
  59.  
  60. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  61. #
  62. #location ~ \.php$ {
  63. # root html;
  64. # fastcgi_pass 127.0.0.1:;
  65. # fastcgi_index index.php;
  66. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  67. # include fastcgi_params;
  68. #}
  69.  
  70. # deny access to .htaccess files, if Apache's document root
  71. # concurs with nginx's one
  72. #
  73. #location ~ /\.ht {
  74. # deny all;
  75. #}
  76. }
  77.  
  78. # another virtual host using mix of IP-, name-, and port-based configuration
  79. #
  80. #server {
  81. # listen ;
  82. # listen somename:;
  83. # server_name somename alias another.alias;
  84.  
  85. # location / {
  86. # root html;
  87. # index index.html index.htm;
  88. # }
  89. #}
  90.  
  91. # HTTPS server
  92. #
  93. #server {
  94. # listen ssl;
  95. # server_name localhost;
  96.  
  97. # ssl_certificate cert.pem;
  98. # ssl_certificate_key cert.key;
  99.  
  100. # ssl_session_cache shared:SSL:1m;
  101. # ssl_session_timeout 5m;
  102.  
  103. # ssl_ciphers HIGH:!aNULL:!MD5;
  104. # ssl_prefer_server_ciphers on;
  105.  
  106. # location / {
  107. # root html;
  108. # index index.html index.htm;
  109. # }
  110. #}
  111.  
  112. }

Nginx默认配置

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

  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.下载源代码

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

3.解压缩

  1. tar -zxvf nginx-1.12..tar.gz

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

  1. ./configure --prefix=/opt/nginx112/
  2. make
  3. make install

5.进入nginx安装好的目录

  1. cd /opt/nginx112/

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

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

9.学习nginx.conf 核心配置

  1. #nginx web核心功能在这里已定义
  2. http {
  3. #定义nginx虚拟主机的
  4. server {
  5. #nginx监听的端口,默认浏览器是80
  6. listen ;
  7. #填写服务器的域名,如果你有域名,nginx会解析到当前这个虚拟主机
  8. #当我访问pythonav.cn:
  9. server_name pythonav.cn;
  10.  
  11. #location就是nginx的路径资源匹配,
  12. #就是当我请求
  13. #pythonav.cn
  14. #pythonav.cn/man.jpg
  15. #pythonav.cn/av/pian.mp4
  16. #这个 location / 这个语法是万能匹配,你所有的请求,都会进入这个location
  17. location / {
  18. #这个root参数,用于定义网页根目录,路径
  19. root html;
  20. #定义网页的首页文件,名字且必须叫做index.html
  21. index index.html index.htm;
  22. }
  23.  
  24. error_page /.html;
  25. }
  26.  
  27. }

10.nginx多虚拟主机

ip 和域名的关系 一对多

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

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

  1. http{
  2. #虚拟主机1,我门用它运行,吃鸡网站
  3. server{
  4. listen ;
  5. #当我访问的域名是 s16chiji.com ,就进入这个server标签
  6. server_name s16chiji.com;
  7. location / {
  8. #返回/opt/s16chiji目录下的内容
  9. root /opt/s16chiji/;
  10. index index.html;
  11. }
  12. }
  13. #虚拟主机2,用它运行,s16韩剧网站
  14. server{
  15. listen ;
  16. server_name s16hanju.com;
  17. location / {
  18. root /opt/s16hanju;
  19. index index.html;
  20. }
  21. }
  22.  
  23. }

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

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

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

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

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

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;
  4.  
  5. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  6. '$status $body_bytes_sent "$http_referer" '
  7. '"$http_user_agent" "$http_x_forwarded_for"';
  8.  
  9. access_log logs/access.log main;

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

  1. 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. 《Python自动化运维之路》 系统基础信息模块(一)

    系统性能收集模块Psutil 目录: 系统性能信息模块psutil 系统性能信息模块psutil psutil能够轻松实现获取系统运行的进程和系统利用率包括(CPU,内存,磁盘 和网络)等.主要用于系 ...

  2. BZOJ NOIP提高组十连测第一场

    今天的题目一共拿了$180$分,感觉自己还是太菜了,二三两题只能骗到部分分 1.$String\ Master$ 题目大意:有两个字符串,在允许k次失配的情况下,求最长公共子串的长度 没什么好讲,直接 ...

  3. 移动一根火柴使等式成立js版本(递归)

    修改成递归版本 思路: 1.设定规则数组,比如:1加一根火柴只可以变成7. 2.设定方法数组,比如:一个数增加了一根火柴,其他的数必然减少一根火柴. 3.增加Array方法,由元素名和方法,得到规则对 ...

  4. 【小程序开放激励视频】--wepy小程序添加激励视频

    小程序开放激励视频是对小程序开发者一个福音,小程序开发者可以完成一些变现,以增加收入! 本文章针对已经有开发经验或者正在进行小程序开发的同学~ 官方文档:激励视频广告 定义页面变量,用于创建视频实例 ...

  5. Android MediaPlayer setDataSource failed

    今天在尝试使用MediaPlayer播放音乐时出了一个问题,在使用 mp.setDataSource(this,Uri.parse("/sdcard/Music/adele.mp3" ...

  6. Selenium3 + Python3自动化测试系列三——控制浏览器操作

    控制浏览器操作 控制浏览器窗口大小 在测试过程中,我们在打开浏览器后,根据需求可自定义调整浏览器的尺寸大小.WebDriver提供了set_window_size()方法来设置浏览器的大小. 如果页面 ...

  7. GCC C语言 DLL范例,含源码

    作者:小白救星 编译:gcc -c -DBUILDING_HZ_DLL1 hzdll1.c           gcc -shared -o hzdll1.dll hzdll1.o -Wl,--kil ...

  8. Redis笔记(1)数据结构与对象

    1.前言 此系列博客记录redis设计与实现一书的笔记,提取书本中的知识点,省略相关说明,方便查阅. 2.基本数据结构 2.1 简单动态字符串SDS(simple dynamic string) 结构 ...

  9. php数组方法

    查找.筛选与搜索数组元素是数组操作的一些常见功能.下面来介绍一下几个相关的函数. in_array()函数 in_array()函数在一个数组汇总搜索一个特定值,如果找到这个值返回true,否则返回f ...

  10. 面试题---实现strcpy函数

    #include <stdio.h> char *strcpy(char *strDest,char *strSrc) { if(strDest == NULL || strSrc == ...