一、nginx的安装、启动、停止及文件解读

准备工作:

yum -y install gcc gcc-c++ autoconf pcre-devel make automake
yum -y install wget httpd-tools vim

(1)基于Yum的方式安装Nginx

  我们可以先来查看一下yum是否已经存在,命令如下:

yum list | grep nginx

  配置nginx下载源:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

  将上述代码写入  /etc/yum.repos.d/nginx.repo  中

 yum install nginx
nginx -v

(2)查看nginx安装目录

 rpm -ql nginx

  rpm 是linux的rpm包管理工具,-q 代表询问模式,-l 代表返回列表。

(3)nginx.conf文件解读

  nginx.conf 文件是Nginx总配置文件,在我们搭建服务器时经常调整的文件。

cd /etc/nginx
vim nginx.conf
 #运行用户,默认即是nginx,可以不进行设置
user nginx;
#Nginx进程,一般设置为和CPU核数一样
worker_processes ;
#错误日志存放目录
error_log /var/log/nginx/error.log warn;
#进程pid存放位置
pid /var/run/nginx.pid; events {
worker_connections ; # 单个后台进程的最大并发数
} http {
include /etc/nginx/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 /var/log/nginx/access.log main; #nginx访问日志存放位置 sendfile on; #开启高效传输模式
#tcp_nopush on; #减少网络报文段的数量 keepalive_timeout ; #保持连接的时间,也叫超时时间 #gzip on; #开启gzip压缩 include /etc/nginx/conf.d/*.conf; #包含的子配置项位置和文件

(4)default.conf 配置项讲解

  进入conf.d目录,然后使用 vim default.conf 进行查看。

 server {
listen ; #配置监听端口
server_name localhost; //配置域名 #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html; #服务默认启动目录
index index.html index.htm; #默认访问文件
} #error_page /.html; # 配置404页面 # redirect server error pages to the static page /50x.html
#
error_page /50x.html; #错误状态码的显示页面,配置后需要重启
location = /50x.html {
root /usr/share/nginx/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;
#}
}

  得知服务目录放在了/usr/share/nginx/html

(5)nginx启动、停止、重启

  启动

    在centos7以上使用命令 nginx 可直接启动

    使用systemctl命令启动 systemctl start nginx.service

    使用 ps aux | grep nginx 查看服务开启状况

    使用 netstat -lunpt 可查看端口开启状况

  停止    

 nginx  -s stop
nginx -s quit
killall nginx
systemctl stop nginx.service

  重启

systemctl restart nginx.service
nginx -s reload

  

nginx基础(一)的更多相关文章

  1. Nginx基础整理

    目录结构如下: Nginx基础知识 Nginx HTTP服务器的特色及优点 Nginx的主要企业功能 Nginx作为web服务器的主要应用场景包括: Nginx的安装 安装环境 快速安装命令集合 各个 ...

  2. nginx 基础文档

    Nginx基础 1.  nginx安装 2.  nginx 编译参数详解 3.  nginx安装配置+清缓存模块安装 4.  nginx+PHP 5.5 5.  nginx配置虚拟主机 6.  ngi ...

  3. Nginx基础教程PPT

    Nginx基础教程PPT By 马冬亮(凝霜  Loki) 一个人的战争(http://blog.csdn.net/MDL13412) pdf版本号下载 watermark/2/text/aHR0cD ...

  4. Linux - nginx基础及常用操作

    目录 Linux - nginx基础及常用操作 Tengine淘宝nginx安装流程 nginx的主配置文件nginx.conf 基于域名的多虚拟主机实战 nginx的访问日志功能 网站的404页面优 ...

  5. Nginx基础知识介绍

    Nginx基础知识介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx概述 Nginx是免费的.开源的.高性能的HTTP和正向/反向代理服务器.邮件代理服务器.以及T ...

  6. [转帖]nginx基础整理

    nginx基础整理 https://www.cnblogs.com/guigujun/p/6588545.html 目录结构如下: Nginx基础知识 Nginx HTTP服务器的特色及优点 Ngin ...

  7. 原创——Nginx基础

    Nginx基础 一.Nginx概述: Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx ...

  8. Nginx基础优化

    Nginx基础优化 1.隐藏nginx header版本号 1.1查看版本号 [root@Nginx ~]# curl -I http://www.yunwei.cn HTTP/1.1 200 OK ...

  9. Nginx基础详细讲解

    Nginx基础详细讲解 链接:https://pan.baidu.com/s/1xB20bnuanh0Avs4kwRpSXQ 提取码:migq 复制这段内容后打开百度网盘手机App,操作更方便哦 1. ...

  10. nginx基础(二)

    二.nginx基础配置 (1)错误指向一个页面 http状态指向指定访问页面,在 /etc/nginx/conf.d/default.conf 中配置 error_page /50x.html; er ...

随机推荐

  1. FreeImage 结合 VB6 使用技巧

    1.图片(Bitmap)改变为32位使用FreeImage_ConvertColorDepth函数.图片半透明绘制需要图片(Bitmap)是32位的. 2.图片(Bitmap)的半透明绘制使用函数:F ...

  2. Windows玩转Kubernetes系列2-Centos安装Docker

    接上一章,Windows玩转Kubernetes系列1-VirtualBox安装Centos,我们开始学习如何在Centos中安装Docker 准备 关闭防火墙 防火墙一定要提前关闭,否则在后续安装K ...

  3. CentOS7 zabbix4.0搭建配置

    一.Zabbix-Server服务器端的安装 概述:10050是Agent的端口,Agent采用被动方式,Server主动连接Agent的10050端口:10051是Server的端口,Agent采用 ...

  4. docker相关----解决tomcat容器启动成功,无法访问的问题

    使用docker安装了tomcat镜像,默认为latest最新的(8.5.50版本),依据tomcat镜像创建容器并同时做了端口映射 命令为:docker run --name tomcat01 -d ...

  5. CTF--HTTP服务--SSI注入

    开门见山 1. 扫描靶场ip,发现VM 192.168.31.160 2. 扫描主机服务信息和服务版本 3. 快速扫描靶场全部信息 4. 探测开放的http的敏感信息 5. 再用dirb扫描敏感页面 ...

  6. oracle问题之SYSTEM表空间不足 (二)

    杂症二.SYSTEM表空间不足报错 一.杂症: PLSQL登录,报错: ORA-00604: 递归 SQL 层  出现错误 ORA-01653: 表.无法通过(在表空间中)扩展 ORA-02002: ...

  7. FFMPEG学习----使用SDL播放PCM数据

    参考雷神的代码: /** * 最简单的SDL2播放音频的例子(SDL2播放PCM) * Simplest Audio Play SDL2 (SDL2 play PCM) * * 本程序使用SDL2播放 ...

  8. LUA提取免费迅雷账号

    --获取http://www.521xunlei.com/ 免费迅雷账号 function getPageid() local http = require("socket.http&quo ...

  9. qt QSplitter分割窗口

    #include <QApplication> #include <QFont> #include <QTextEdit> #include <QSplitt ...

  10. jQuery初学者笔记 一

    jQuery初学者笔记 一 Mirror王宇阳 by jQuery语法 jQuery语法是通过选取HTML元素,并对选取的元素进行操作 基础语法: 所有jQuery语句用"$"符号 ...