资讯专栏INFORMATION COLUMN

Nginx笔记(一)Nginx安装

shinezejian / 765人阅读

摘要:环境准备准备服务器确保有网络确保可用关闭规则查看规则关闭规则保险起见,再查看下查表里是否有规则有的话,也关闭关闭策略查看是否开启关闭安装基础库开始安装访问官网复制以下源服务器上创建的源改成验证源从源安装验证显示如下启动

环境准备

准备服务器
centos7.2

确保有网络

ping www.baidu.com

确保yum可用

yum list | grep gcc

关闭iptables规则

# 查看iptables规则
iptables -L
# 关闭iptables规则
iptables -F
# 保险起见,再查看下查nat表里是否有规则
iptables -t nat -L
# 有的话,也关闭
iptables -t nat -F

关闭selinux策略

# 查看selinux是否开启
getenforce
# 关闭
setenforce 0

安装基础库

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
开始安装

访问Nginx官网
http://nginx.org/en/linux_pac...

复制以下yum源

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

服务器上创建nginx的yum源

cd /etc/yum.repos.d
vi nginx.repo
# OS/OSRELEASE改成centos/7
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

验证yum源

yum list | grep nginx

...
nginx.x86_64                             1:1.12.2-1.el7_4.ngx           nginx
...

从yum源安装nginx

yum install nginx

验证nginx

nginx -v
# 显示如下
nginx version: nginx/1.12.2

启动Nginx

systemctl start nginx.service

进程确认

ps -aux | grep nginx
root      9384  0.0  0.0  46296   952 ?        Ss   22:30   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     9386  0.0  0.1  46680  1912 ?        S    22:30   0:00 nginx: worker process
root      9388  0.0  0.0 112648   968 pts/0    R+   22:30   0:00 grep --color=auto nginx

访问一下,80默认端口

初始备用目录

cd /opt
mkdir app download logs work backup

备份Nginx配置文件

cp /etc/nginx/nginx.conf /opt/backup
cp /etc/nginx/conf.d/default.conf /opt/backup
相关说明

查看安装过程都创建了哪些文件/目录

rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.12.2
/usr/share/doc/nginx-1.12.2/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx

相关文件和目录的说明

路径 类型 作用
/etc/logrotate.d/nginx 配置文件 Nginx日志轮转,用于logrotate服务的日志切割
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
目录、配置文件 Nginx主配置文件
/etc/nginx/fastcgi_params
/etc/nginx/uwsgi_params
/etc/nginx/scgi_params
配置文件 cgi配置相关,fastcgi配置
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/win-utf
配置文件 编码转换映射文件
/etc/nginx/mime.types 配置文件 设置http协议的Content-Type与扩展名对应关系
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
配置文件 (centos7)配置出系统守护进程管理器的管理方式
/usr/lib64/nginx/modules
/etc/nginx/modules
目录 nginx模块目录
/usr/sbin/nginx
/usr/sbin/nginx-debug
命令 nginx服务的启动终端管理命令
/var/cache/nginx 目录 Nginx的缓存目录
/var/log/nginx 目录 nginx的日志目录

查看安装过程的编译参数

nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC" --with-ld-opt="-Wl,-z,relro -Wl,-z,now -pie"

相关编译参数的说明

编译选项 作用
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
安装目的目录或路径
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
执行对应模块时nginx所保留的临时文件
--user=nginx
--group=nginx
设定Nginx进程启动的用户和用户组
--with-cc-opt=parameters 设置额外的参数将被添加到CFLAGS变量
--with-ld-opt=parameters 设置附加参数,链接系统库
--with-http_sub_status_module Nginx客户端状态
--with-http_random_index_module 目录中随机选择一个随机主页
--with-http_sub_module HTTP内容替换

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39778.html

相关文章

  • Nginx笔记-0-Centos环境下安装

    摘要:如果发现运行只有一行回显,可能是当前端口被占用,使用端口号,默认,如果打印结果为两行或以上,即端口被占用,需要修改配置文件的端口号再重新运行。 概述 记录一下 Nginx 通过安装包以及通过源代码安装两种方式。目标是第一次接触 Nginx 的人也能看懂直接用。 一. 使用安装包配置 Tip: 这种安装方式比较简单,官方文档也说得比较清楚详细。这里搭建的环境是 Centos7, 可以sy...

    BlackFlagBin 评论0 收藏0
  • Nginx笔记-0-Centos环境下安装

    摘要:如果发现运行只有一行回显,可能是当前端口被占用,使用端口号,默认,如果打印结果为两行或以上,即端口被占用,需要修改配置文件的端口号再重新运行。 概述 记录一下 Nginx 通过安装包以及通过源代码安装两种方式。目标是第一次接触 Nginx 的人也能看懂直接用。 一. 使用安装包配置 Tip: 这种安装方式比较简单,官方文档也说得比较清楚详细。这里搭建的环境是 Centos7, 可以sy...

    Rindia 评论0 收藏0
  • Linux云计算高端架构师+DevOps高级虚拟化高级进阶视频

    摘要:课程大纲开班典礼开班典礼开班典礼操作系统系统安装及启动流程操作系统系统安装及启动流程必备命令讲解必备命令讲解必备命令讲解及系统启动流程必备命令讲解及系统启动流程启动流程和用户及用户组讲解启动流程和用户及用户组讲解用户权限讲解及编辑器用户权限 课程大纲1.开班典礼(1)_rec.mp42.开班典礼(2)_rec.mp43.开班典礼(3)_rec.flv4.Linux操作系统系统安装及启动...

    Cheng_Gang 评论0 收藏0
  • 安装配置gunicorn和NGINX的学习笔记

    摘要:博客写得差不多了,打算部署到云上因为速度的关系,不打算部署在上,于是申请了阿里云,环境是上篇文章提到的位安装和配置好和,又稍微了解点服务器的知识后,打算按这里的方法进行部署,思路是用当应用容器,当反向代理安装安装非常简单,一条命令就解决了测 博客写得差不多了,打算部署到云上因为速度的关系,不打算部署在AWS上,于是申请了阿里云,环境是上篇文章提到的CentOS 7 64位安装和配置好P...

    Ali_ 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<