1,安装过程

  1. [root@VM_1_14_centos ~]# cd /data/
  2. [root@VM_1_14_centos data]# wget http://nginx.org/download/nginx-1.15.7.tar.gz
  3. [root@VM_1_14_centos data]# tar -xvf nginx-1.15..tar.gz
  4. [root@VM_1_14_centos data]# mkdir //usr/local/nginx -p
  5. [root@VM_1_14_centos data]# ll
  6. total
  7. drwxr-xr-x Dec : nginx-1.15.
  8. -rw-r--r-- root root Nov : nginx-1.15..tar.gz
  9. [root@VM_1_14_centos data]# cd nginx-1.15./
  10. [root@VM_1_14_centos nginx-1.15.]# ./configure --prefix=/usr/local/nginx
  11. [root@VM_1_14_centos nginx-1.15.]#make&&make install

2,假设服务器外网IP为129.129.129.129,需要通过web访问的index文件是  /usr/index.html,index.html文件内容是:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <h1>标题1</h1>
  9. <h2>标题2</h2>
  10. <h3>标题3</h3>
  11. <h4>标题4</h4>
  12. <h5>标题5</h5>
  13. <h6>标题6</h6>
  14. <h7>标题7</h7>
  15. </body>
  16. </html>

同时,需要访问某个图片文件/usr/1.png

3,此时我们需要配置nginx

  1. [root@VM_1_14_centos /]# cd /usr/local/nginx/conf/
  2. [root@VM_1_14_centos conf]#
  3. [root@VM_1_14_centos conf]#
  4. [root@VM_1_14_centos conf]#
  5. [root@VM_1_14_centos conf]# vim nginx.conf
  6.  
  7. #user nobody;
  8. worker_processes ;
  9.  
  10. #error_log logs/error.log;
  11. #error_log logs/error.log notice;
  12. #error_log logs/error.log info;
  13.  
  14. #pid logs/nginx.pid;
  15.  
  16. events {
  17. worker_connections ;
  18. }
  19.  
  20. http {
  21. include mime.types;
  22. default_type application/octet-stream;
  23.  
  24. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  25. # '$status $body_bytes_sent "$http_referer" '
  26. # '"$http_user_agent" "$http_x_forwarded_for"';
  27.  
  28. #access_log logs/access.log main;
  29.  
  30. sendfile on;
  31. #tcp_nopush on;
  32.  
  33. #keepalive_timeout ;
  34. keepalive_timeout ;
  35.  
  36. #gzip on;
  37.  
  38. server {
  39. listen ;            #这里需要我们设置web访问的端口
  40. server_name 129.xxx.xxx.xxx; #这里设置web访问的IP,最终在浏览器访问 129.xxx.xxx.xxx:80/index.html    
  41.  
  42. #charset koi8-r;
  43.  
  44. #access_log logs/host.access.log main;
  45.  
  46. location / { #这里很重要,原因参考下一行
  47. root /usr; #这里更重要,root是指直接访问 IP:port 时,获取文件的根目录,如果上一行设置为 / ,则直接访问IP:port会去拉取 /usr下面的index.html
  48. index index.html index.htm; #接上一行,如果location后面设置了目录 /abc ,则访问IP:port时,会拉取 /usr/abc/index.html.
  49. }
  50.  
  51. #error_page /.html;
  52.  
  53. # redirect server error pages to the static page /50x.html
  54. #
  55. error_page /50x.html;
  56. location = /50x.html {
  57. root html;
  58. }
  59.  
  60. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  61. #
  62. #location ~ \.php$ {
  63. # proxy_pass http://127.0.0.1;
  64. #}
  65.  
  66. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  67. #
  68. #location ~ \.php$ {
  69. # root html;
  70. # fastcgi_pass 127.0.0.1:;
  71. # fastcgi_index index.php;
  72. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  73. # include fastcgi_params;
  74. #}
  75.  
  76. # deny access to .htaccess files, if Apache's document root
  77. # concurs with nginx's one
  78. #
  79. #location ~ /\.ht {
  80. # deny all;
  81. #}
  82. }
  83.  
  84. # another virtual host using mix of IP-, name-, and port-based configuration
  85. #
  86. #server {
  87. # listen ;
  88. # listen somename:;
  89. # server_name somename alias another.alias;
  90.  
  91. # location / {
  92. # root html;
  93. # index index.html index.htm;
  94. # }
  95. #}
  96.  
  97. # HTTPS server
  98. #
  99. #server {
  100. # listen ssl;
  101. # server_name localhost;
  102.  
  103. # ssl_certificate cert.pem;
  104. # ssl_certificate_key cert.key;
  105.  
  106. # ssl_session_cache shared:SSL:1m;
  107. # ssl_session_timeout 5m;
  108.  
  109. # ssl_ciphers HIGH:!aNULL:!MD5;
  110. # ssl_prefer_server_ciphers on;
  111.  
  112. # location / {
  113. # root html;
  114. # index index.html index.htm;
  115. # }
  116. #}
  117.  
  118. }

4,启动nginx服务,使用上面的配置文件

  1. [root@VM_1_14_centos sbin]# pwd
  2. /usr/local/nginx/sbin
  3. [root@VM_1_14_centos sbin]# ./nginx -t #检查配置文件是否正确无误
  4. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  5. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  6. [root@VM_1_14_centos sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf #使用上一步配置的nginx.conf启动nginx服务
  7. [root@VM_1_14_centos sbin]# ps -aux | grep nginx
  8. root 0.0 0.0 ? Ss : : nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
  9. nobody 0.0 0.0 ? S : : nginx: worker process
  10. root 0.0 0.0 pts/ S+ : : grep --color=auto nginx

5,使用浏览器打开对应IP:port

如上图,直接访问IP,会使用默认端口80并拉取index.html.

如果我们需要访问web服务器上的1.png图片,只需要访问url    129.xxx.xxx.xxx:80/1.png,若端口号设置为80时,在浏览器中访问也可以不带端口号。

【Finished】

附:

nginx常用命令

./nginx -s reload          重启nginx

./nginx -s stop             停止nginx

【CentOS 7】nginx配置web服务器的更多相关文章

  1. centos从头学习配置web服务器环境

    为了学习linux下配置web服务器环境,于是安装了vmware,准备在虚拟机里面学习web服务器的搭建! 首先是在虚拟机里安装centos,我选择的是32位的centos6.6版本,因为新版本7据说 ...

  2. Centos下Nginx配置WEB访问日志并结合shell脚本定时切割

    在一个成熟的WEB系统里,没有日志管理是不可以的,有了日志,可以帮助你得到用户地域来源.跳转来源.使用终端.某个URL访问量等相关信息:通过错误日志,你可以得到系统某个服务或server的性能瓶颈等. ...

  3. nginx配置web服务器

    一:设置虚拟服务器 1.设置 http { server { listen 127.0.0.1:8080; server_name example.org www.example.org; } } 2 ...

  4. linux centOS下怎么配置web服务器

    | 浏览:4503 | 更新:2011-12-07 17:45 1 2 3 分步阅读 下是我在配置web服务时作的一些记录,高手飘开或者看了指点一下,不胜感激,第一次配置,很多细节需要自己优化.适合环 ...

  5. linux使用nginx配置web服务器

    环境: CenterOS 7 1.安装nginx之前先安装nginx所需的依赖包 yum -y install zlib zlib-devel openssl openssl-devel pcre p ...

  6. nginx高性能WEB服务器系列之六--nginx负载均衡配置+健康检查

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  7. nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  8. nginx配置图片服务器

    这几天研究了一下nginx配置图片服务器的相关内容,个人的一些收获与大家分享一下: Nginx是目前非常流行的web服务器,它起源于俄罗斯.它具有处理速度快,并发量大,占用资源极低等优点,尤其对于静态 ...

  9. NGINX高性能Web服务器详解(读书笔记)

    原文地址:NGINX高性能Web服务器详解(读书笔记) 作者:夏寥寥 第4章  Nginx服务器的高级配置 4.1 针对IPv4的内核7个参数的配置优化 说明:我们可以将这些内核参数的值追加到Linu ...

随机推荐

  1. PostgreSQL学习----模式schema

    PostgreSQL学习---模式schema 小序 接触PostgreSQL也有好长时间了,知识不总结梳理,似乎总不是自己的,继续努力吧少年!以此记录我的软件工艺之路! 模式(Schema) 一个 ...

  2. 【CF1009F】Dominant Indices

    题目 长链剖分板子题啊 长链剖分有几个神奇的性质 所有长链的总点数为\(n\) 任意一个点的\(k\)级祖先所在长链的长度肯定不小于\(k\) 从任意点到根经过的短边数量不超过\(\sqrt{n}\) ...

  3. net mvc中实现记录用户登录信息(记住登录效果)

    现记录用户登录信息(记住登录效果) 本文讲述了使用cookies实现网站记住登录效果,效果如下: 主要实现方法,当用户选择记住登录时建立cookies保存用户名和用户密码,当用户登录不选择记住登录时, ...

  4. Hadoop学习之路(八)在eclispe上搭建Hadoop开发环境

    一.添加插件 将hadoop-eclipse-plugin-2.7.5.jar放入eclipse的plugins文件夹中 二.在Windows上安装Hadoop2.7.5 版本最好与Linux集群中的 ...

  5. 微信小程序、安卓APP、苹果APP对比分析

    今天的话题主要是关于微信小程序.安卓APP.苹果APP对比分析.既然是对比分析肯定是将它们一个一个说明. 本篇不涉及技术话题,只讲解微信小程序.安卓APP.苹果APP它们各自的优缺点及其应用场景. 一 ...

  6. python 工具 eclipse pydev工具安装。

    1.下载eclipse 2.下载java jre(这个会在运行eclipse的时候提示你下载,,根据系统型号下载就行) 3.下载完jre后,把目录下javaw.exe的路径添加到系统path环境变量中 ...

  7. 论文笔记 Pose-driven Deep Convolutional Model for Person Re-identification_tianqi_2017_ICCV

    1. 摘要 为解决姿态变化的问题,作者提出Pose-driven-deep convolutional model(PDC),结合了global feature跟local feature, 而loc ...

  8. 《You dont know JS》原生函数

    原生函数 原生函数,即JavaScript的内建函数(built-in function).常用的原生函数有String().Number().Boolean().Array().Object().F ...

  9. iPhone将NSString转换编码集为gb2312或者gbk的方法

    很多时候软件读取的中文网页编码集是gb2312,所以显示出来的是乱码.这时需要将NSString文字编码转换.你可以试试以下代码 NSURL *url = [NSURL URLWithString:u ...

  10. PHP操作xml学习笔记之增删改查(1)—增加

    xml文件 <?xml version="1.0" encoding="utf-8"?><班级>    <学生>       ...