一、Nginx快速搭建与基参数使用
下载地址:http://nginx.org/en/download.html
Mainline version 开发版,研究学习用
Stable version 稳定版本,官方认可,测试稳定的
Legacy versions 历史版本
Linux稳定版:http://nginx.org/download/nginx-1.12.2.tar.gz
Windows稳定版:http://nginx.org/download/nginx-1.12.2.zip
官方yum源:http://nginx.org/en/linux_packages.html#stable
安装方法:/technology/3303
二、基本参数使用
1、安装目录
rpm -ql nginx # 查看nginx配置文件 # 输出结果 /etc/logrotate.d/nginx # 配置文件,nginx日志轮转,用于logrotate服务的日志切割(定时切割日志) /etc/nginx/fastcgi.conf # cgi配置相关 /etc/nginx/fastcgi.conf.default # cgi配置相关 /etc/nginx/fastcgi_params # cgi配置相关 /etc/nginx/fastcgi_params.default # cgi配置相关 /etc/nginx/koi-utf # 编码转换映射转化文件 /etc/nginx/koi-win # 编码转换映射转化文件 /etc/nginx/mime.types # 设置http协议的Content-Type与扩展名对应关系 /etc/nginx/mime.types.default # 设置http协议的Content-Type与扩展名对应关系 /etc/nginx/nginx.conf # 配置文件,主配置文件 /etc/nginx/nginx.conf.default # 配置文件,主配置文件 /etc/nginx/scgi_params # cgi配置相关 /etc/nginx/scgi_params.default # cgi配置相关 /etc/nginx/uwsgi_params # cgi配置相关 /etc/nginx/uwsgi_params.default # cgi配置相关 /etc/nginx/win-utf # 编码转换映射转化文件 /usr/bin/nginx-upgrade /usr/lib/systemd/system/nginx.service # 用于配置出系统守护进程管理器管理方式 /usr/lib64/nginx/modules # nginx模块目录 /usr/sbin/nginx # nginx服务的启动管理的终端命令 /usr/share/doc/nginx-1.12.2 # nginx的手册和帮助文件 /usr/share/doc/nginx-1.12.2/CHANGES # nginx的手册和帮助文件 /usr/share/doc/nginx-1.12.2/README # nginx的手册和帮助文件 /usr/share/doc/nginx-1.12.2/README.dynamic # nginx的手册和帮助文件 /usr/share/doc/nginx-1.12.2/UPGRADE-NOTES-1.6-to-1.10 # nginx的手册和帮助文件 /usr/share/licenses/nginx-1.12.2 /usr/share/licenses/nginx-1.12.2/LICENSE /usr/share/man/man3/nginx.3pm.gz # nginx的手册和帮助文件 /usr/share/man/man8/nginx-upgrade.8.gz # nginx的手册和帮助文件 /usr/share/man/man8/nginx.8.gz # nginx的手册和帮助文件 /usr/share/nginx/html/404.html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html /usr/share/nginx/html/nginx-logo.png /usr/share/nginx/html/poweredby.png /usr/share/vim/vimfiles/ftdetect/nginx.vim /usr/share/vim/vimfiles/indent/nginx.vim /usr/share/vim/vimfiles/syntax/nginx.vim /var/lib/nginx /var/lib/nginx/tmp /var/log/nginx # nginx的日志目录
2、编译参数
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=/usr/share/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 # 安装目录 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body # 执行对应模块时,nginx所保存的临时性文件 --http-proxy-temp-path=/var/lib/nginx/tmp/proxy # 执行对应模块时,nginx所保存的临时性文件 --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi # 执行对应模块时,nginx所保存的临时性文件 --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi # 执行对应模块时,nginx所保存的临时性文件 --http-scgi-temp-path=/var/lib/nginx/tmp/scgi # 执行对应模块时,nginx所保存的临时性文件 --pid-path=/run/nginx.pid # 安装目录 --lock-path=/run/lock/subsys/nginx # 安装目录 --user=nginx # 设定nginx进程启动的用户和组用户 --group=nginx # 设定nginx进程启动的用户和组用户 --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong # 设置额外的参数将被添加到CFLAGS变量 --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' # 设置附加的参数,链接系统库
3、基本配置语法
vim /etc/nginx/nginx.conf # 编辑主配置文件 # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user root; # 设置nginx服务的系统使用用户 worker_processes auto; # 工作进程数,尽量和CPU个数一致即可 error_log /var/log/nginx/error.log; # nginx的错误日志 pid /run/nginx.pid; # nginx服务启动时候pid # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; # 每个进程允许最大链接数 } 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; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; # 超时时间,单位秒 types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; # 读取该目录下所有.conf文件 server { listen 80 default_server; listen [::]:80 default_server; server_name pro.ject.club; root /root/workspace/; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; # 读取该目录下所有.conf文件 location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }