安装Nginx
添加Nginx的yum存储库
vim /etc/yum.repos.d/nginx.repo
//在文件中加入
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
检查验证yum存储库是否添加
yum repolist | grep nginx
//显示
nginx/x86_64 nginx repo 136
安装Nginx
yum install nginx
//显示
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 nginx.x86_64.1.1.14.2-1.el7_4.ngx 将被 安装
--> 解决依赖关系完成
.
.
.
安装 1 软件包
总下载量:754 k
安装大小:2.6 M
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.14.2-1.el7_4.ngx.x 47% [=======- ] 9.5 kB/s | 360 kB 00:41 ETA
.
.
.
----------------------------------------------------------------------
验证中 : 1:nginx-1.14.2-1.el7_4.ngx.x86_64 1/1
已安装:
nginx.x86_64 1:1.14.2-1.el7_4.ngx
完毕!
启动Nginx
systemctl start nginx
IP访问
到此Nginx安装完成
Nginx的目录
查看Nginx的版本号
nginx -v
//显示
nginx version: nginx/1.14.2
查看Nginx安装哪些目录到系统中
rpm -ql yum源名称(/etc/yum.repos.d/nginx)
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.14.2
/usr/share/doc/nginx-1.14.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 | 目录、配置文件 | Nginx主配置文件 |
/etc/nginx/nginx.conf | ||
/etc/nginx/conf.d | ||
/etc/nginx/conf.d/default.conf | ||
/etc/nginx/fastcgi_params | 配置文件 | cgi配置相关,fastcgi配置 |
/etc/nginx/uwsgi_params | ||
/etc/nginx/scgi_params | ||
/etc/nginx/koi-utf | 配置文件 | 编码转换映射转化文件 |
/etc/nginx/koi-win | ||
/etc/nginx/win-utf | ||
/etc/nginx/mime.types | 配置文件 | 设置http协议的Conten-Type与扩展名对应关系 |
/usr/lib/systemd/system/nginx-debug.service | 配置文件 | 用于配置出系统守护进程管理器管理方式 |
/usr/lib/systemd/system/nginx.service | ||
/etc/sysconfig/nginx | ||
/etc/sysconfig/nginx-debug | ||
/usr/lib64/nginx/modules | 目录 | Nginx模块目录 |
/etc/nginx/modules | ||
/usr/sbin/nginx | 命令 | Nginx服务的启动管理的终端命令 |
/usr/sbin/nginx-debug | ||
/usr/share/doc/nginx-1.14.2 | 文件、目录 | Nginx的手册和帮助文件 |
/usr/share/doc/nginx-1.14.2/COPYRIGHT | ||
/usr/share/man/man8/nginx.8.gz | ||
/var/cache/nginx | 目录 | Nginx的缓存目录 |
/var/log/nginx | 目录 | Nginx的日志目录 |
查看Nginx编译的参数
nginx -V
//显示
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (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 | 设定Nginx进程启动的用户和组用户 |
--group=nginx | |
--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' | 设置额外的参数将添加到CFLAGS变量 |
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' | 设置附加的参数,链接系统库 |
Nginx的配置语法
cat /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
user | 设置nginx服务的系统使用用户 |
---|---|
worker_processes | 工作进程数 |
error_log | nginx的错误日志 |
pid | nginx服务启动时候pid |
events | worker_connections | 每个进程允许最大连接数 |
---|---|---|
use | 工作进程数 |