nginx的yum安裝,基本參數使用,編譯參數說明和Nginx基本配置,模塊安裝

nginx的yum安裝
從nginx官網獲取源php

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=1html

yum install ngnxlinux

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/nginxnginx

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'json

基礎路徑
--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 vim

--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 centos

設置額外的參數將被添加到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服務啓動時的Pidapp

events {
worker_connections 每一個進程的最大鏈接數
use io模型
}dom

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內置的
自定義變量:本身定義

模塊安裝

好比要安裝 :ngx_http_realip_module

獲取以前的在安裝編譯參數

nginx -V
--group=nginx --user=nginx --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.41

從新編譯,編譯參數後面加上

--with-http_realip_module

進入源碼目錄

./configure 
--group=nginx --user=nginx --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.41 --with-http_realip_module

make
不make install
make完以後在objs目錄下就多了個nginx
替換現有的nginx便可

相關文章
相關標籤/搜索