码迷,mamicode.com
首页 > 其他好文 > 详细

nginx的yum安装,基本参数使用,编译参数说明和Nginx基本配置语法

时间:2017-10-08 22:39:36      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:location   模型   receive   libcurl   app   nginx变量   arguments   page   none   

nginx的yum安装
从nginx官网获取源

vim /etc/yum.repose.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
OS改为centos
OSRELEASE改为当前系统版本
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

yum install ngnx

技术分享
rpm -ql nginx
[root@localhost110 sbin]# rpm -ql nginx
/etc/logrotate.d/nginx          配置文件   nginx日志轮转,用于logrotata服务的日志切割
/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/rc.d/init.d/nginx
/etc/rc.d/init.d/nginx-debug
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.12.1
/usr/share/doc/nginx-1.12.1/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
View Code

目录说明
/etc/logrotate.d/nginx 配置文件 nginx日志轮转,用于logrotata服务的日志切割
目录配置文件
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/nginx.conf
配置文件cgi,fastcgi相关配置
/etc/nginx/fastcgi_params
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
配置文件,编码转换映射转化文件
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/win-utf
配置文件,设置http协议的content-type与扩展名对应文件
/etc/nginx/mime.types
用于配置出系统守护进程管理器管理方式
/etc/rc.d/init.d/nginx
/etc/rc.d/init.d/nginx-debug
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
nginx模块目录
/etc/nginx/modules
/usr/lib64/nginx/modules
nginx服务的启动管理终端命令
/usr/sbin/nginx
/usr/sbin/nginx-debug
手册和帮助文件
/usr/share/doc/nginx-1.12.1
/usr/share/doc/nginx-1.12.1/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
缓存目录
/var/cache/nginx
日志目录
/var/log/nginx

2.nginx的编译参数
nginx -V
[root@localhost110 sbin]# ./nginx -V
nginx version: nginx/1.12.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
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 --param=ssp-buffer-size=4 -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
执行对应模块时,nginx保留的临时目录
--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

设置额外的参数将被添加到CFLAGS变量
--with-cc-opt=‘-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC‘
设置的附加参数,链接到系统库
--with-ld-opt=‘-Wl,-z,relro -Wl,-z,now -pie‘

nginx的基础配置语法
user:设置nginx服务的系统使用用户
worker_processes:工作进程数(和cpu核心数保持一致最好)
error_log:错误日志
pid:nginx服务启动时的Pid

events {
worker_connections 每个进程的最大连接数
use io模型
}

curl -v 查看请求

技术分享
curl -v http://192.168.1.251/1.html 
* About to connect() to 192.168.1.251 port 80 (#0)
*   Trying 192.168.1.251... connected
* Connected to 192.168.1.251 (192.168.1.251) port 80 (#0)
> GET /1.html HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.251
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.12.1
< Date: Fri, 06 Oct 2017 14:11:25 GMT
< Content-Type: text/html
< Content-Length: 7
< Last-Modified: Fri, 06 Oct 2017 14:10:08 GMT
< Connection: keep-alive
< ETag: "59d78ec0-7"
< Accept-Ranges: bytes
< 
1.html
* Connection #0 to host 192.168.1.251 left intact
* Closing connection #0

 curl -v http://192.168.1.251/1.html >/dev/null
* About to connect() to 192.168.1.251 port 80 (#0)
*   Trying 192.168.1.251... connected
* Connected to 192.168.1.251 (192.168.1.251) port 80 (#0)
> GET /1.html HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.251
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.12.1
< Date: Fri, 06 Oct 2017 14:12:02 GMT
< Content-Type: text/html
< Content-Length: 7
< Last-Modified: Fri, 06 Oct 2017 14:10:08 GMT
< Connection: keep-alive
< ETag: "59d78ec0-7"
< Accept-Ranges: bytes
< 
{ [data not shown]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     7    0     7    0     0   2266      0 --:--:-- --:--:-- --:--:--     0* Connection #0 to host 192.168.1.251 left intact

* Closing connection #0
View Code

页面定制

error_page 404 /404.html;
location = /404.html{
  return 404 "not find!";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
比如关闭php-fpm后产生502会定位到/50x.html

return http状态码 string
return 200 内容
return 301 跳转到的链接
location ~ ^/getjson{
default_type application/json;
return 200 {"status":1,"note":"ok"};
}

location ~* ^/nums/(\d+)([a-z]+)\.html {
set $d $1;
set $s $2;
return 200 str:$d$s;
}
http://192.168.1.251/nums/2017abcE.html
str:2017abcE
#防止乱码
location /txt {
default_type text/html;
add_header Content-Type text/html;charset=utf-8;
return 200 "nginx你好";
}

日志类型

error.log access_log

 

log_format
Syntax: log_format name [escape=default|json] string .....;
Default: log_format combined "....";
Context:http

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变量
HTTP请求变量
arg_PARAMETER,http_HEADER,sent_http_HEADER
内置变量: nginx内置的
自定义变量:自己定义

 

nginx的yum安装,基本参数使用,编译参数说明和Nginx基本配置语法

标签:location   模型   receive   libcurl   app   nginx变量   arguments   page   none   

原文地址:http://www.cnblogs.com/HKUI/p/7638577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!