一、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

  

最新文章

  1. C++命名空间问题
  2. Xcode插件安装
  3. python模块基础之json,requeste,xml,configparser,logging,subprocess,shutil。
  4. codeforces #round363 div2.C-Vacations (DP)
  5. POJ 3258 River Hopscotch (binarysearch)
  6. MySQL的相关设置
  7. C语言学习——C和Java语言不同点
  8. html ui设计案例
  9. MySQL5.6安装(RPM)笔记
  10. http目录显示时间与服务器相差8小时
  11. python制作词云
  12. Uncaught TypeError: Cannot read property 'getters' of undefined
  13. 刘志梅 201771010115 《面向对象程序设计(java)》 第十八周学习总结
  14. kinect 深度图与彩色图对齐程序
  15. C# ToLookup
  16. mysql之 OPTIMIZE TABLE整理碎片
  17. 绝对路径${pageContext.request.contextPath}用法及其与web.xml中Servlet的url-pattern匹配过程
  18. POJ 2407:Relatives(欧拉函数模板)
  19. 针对ROS5版本的配置导出和导入(迁移其他服务器)
  20. jQuery中的text(),html(),val()的区别

热门文章

  1. IntelliJ IDEA编辑文件的时候CPU飙高问题的解决
  2. sense8影评摘抄
  3. GP工作室—系统设计
  4. mysql--->innodb引擎什么时候表锁什么时候行锁?
  5. a标签跳转小程序
  6. HDU-2647 Reward(链式前向星+拓扑排序)
  7. Git详解之安装
  8. 一文教你一次性完成Helm 3迁移
  9. 解决python报错:ImportError: No module named shutil_get_terminal_size 的方法
  10. Java并发读书笔记:JMM与重排序