nginx安装和配置
来源:互联网 发布:怎么查找淘宝卖家电话 编辑:程序博客网 时间:2024/05/17 21:59
从nginx官网下载安装包 nginx-1.9.12.tar.gz
下载地址 http://nginx.org/
安装所需基础库
yum install pcre-devel
yum install zlib-devel
编译安装nginx
./configure –prefix=/usr/local/nginx
make
make install
查看nginx版本和安装参数
./sbin/nginx -V
conf/nginx.conf
# 使用的用户和组#user nobody;# 指定工作进程数worker_processes 1;# 错误日志保存位置# 可以使用 [ debug | info | notice | warn | error | crit ] 参数#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;# 指定 pid 存放的路径 #pid logs/nginx.pid;# 事件模块events { # 默认使用哪种事件模型,即nginx处理连接的方法 # use [ kqueue | rtsig | epoll | /dev/poll | select | poll | eventport ] use epoll; #每个worker的最大连接数 worker_connections 1024;}# HTTP模块http { # 不同文件后缀对应的MIME include mime.types; # 默认MIME类型为二进制字节流 default_type application/octet-stream; #charset gb2312 # 日志输出格式 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "request_time" "$http_x_forwarded_for"'; # 日志默认输出路径和格式 #access_log logs/access.log main; #server_names_hash_bucket_size 128; #client_header_buffer_size 32k; #large_client_header_buffers 4 64k; #client_max_body_size 100m; #send_timeout 120; # 开启调用Linux的sendfile(),提供文件传输效率 sendfile on; # 是否允许使用socket的TCP_NOPUSH或TCP_CORK选项 #tcp_nopush on; # 指定客户端连接保持活动的超时时间,在这个时间之后,服务器会关掉连接 #keepalive_timeout 0; keepalive_timeout 65; #fastcgi_connect_timeout 300; #fastcgi_send_timeout 300; #fastcgi_read_timeout 300; #fastcgi_buffer_size 64k; #fastcgi_buffers 4 64k; #fastcgi_busy_buffers_size 128k; #fastcgi_temp_file_write_size 128k; #fastcgi_intercept_errors on; # 设置gzip,压缩文件 #gzip on; #gzip_min_length 1k; #gzip_buffers 4 16k; #gzip_http_version 1.0; #gzip_comp_level 2; #gzip_types text/plain application/x-javascript text/css application/xml; #gzip_vary on; # 设定负载均衡的服务器列表 #upstream myproject { # weigth参数表示权值,权值越高被分配到的几率越大 # max_fails 当有#max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查 # fail_timeout 在以后的#fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器 #server 192.168.1.2:8080 weight=5 max_fails=2 fail_timeout=600s; #server 192.168.1.3:8080 weight=3 max_fails=2 fail_timeout=600s; #} server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # 反向代理的配置. # proxy_redirect off; # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # client_max_body_size 10m; #允许客户端请求的最大单文件字节数 # client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数, # proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时) # proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时) # proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时) # proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 # proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 # proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) # proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} # 设定查看Nginx状态的地址 #location /NginxStatus { #stub_status on; #access_log off; #allow 192.168.0.2; #deny all; #auth_basic "NginxStatus"; #auth_basic_user_file conf/htpasswd; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
HTTP模块的核心变量
三个作用域:http, server, location server 语法:server {...} 作用域: http 配置一台虚拟机。 location 语法: location [=|~|~*|^~] /uri/ { ... } 作用域: server 配置访问路径的处理方法。 listen 语法: listen address:port [ default [ backlog=num | rcvbuf=size | sndbuf=size | accept_filter=filter | deferred | bind | ssl ] 默认值: listen 80 作用域: server 指定当前虚拟机的监听端口。 alias 语法: alias file-path|directory-path; 作用域: location 该指令设置指定location使用的路径.注意它跟 root 相似,但是不改变文件的根路径,仅仅是使用文件系统路径 root 语法: root path 默认值:root html 作用域:http, server, location alias指定的目录是准确的,root是指定目录的上级目录,并且该上级目录要含有location指定名称的同名目录。 区别: location /abc/ { alias /home/html/abc/; } 在这段配置下,http://test/abc/a.html就指定的是/home/html/abc/a.html。这段配置亦可改成 location /abc/ { root /home/html/; } 这样,nginx就会去找/home/html/目录下的abc目录了,得到的结果是相同的。 HTTP模块的其他基本组件将结合案例介绍。 变量: HTTP header 里边 特定HEADER的值,变量会转成小写,比如 $http_user_agent, $http_referer... header信息 "YOUR-STRANGE-HEADER: values" 能通过 $http_your_strange_header获得. $arg_PARAMETER $http_HEADER $query_string = $args
启动nginx
./sbin/nginx //启动./sbin/nginx -t //检查nginx.conf格式是否正确./sbin/nginx -s restart //重加载nginx.conf
0 0
- nginx安装和配置
- 安装和配置nginx
- nginx安装和配置
- 安装和配置nginx
- nginx安装和配置
- Nginx 安装和配置
- Nginx安装和配置
- nginx安装和nginx、tomcat集群配置
- 【nginx】Nginx的安装和配置
- nginx和uwsgi安装配置
- Nginx的安装和配置
- Nginx的安装和配置
- nginx的安装和配置
- Nginx的安装和配置
- linux安装和配置nginx
- 1 nginx 安装和配置
- 【服务器】nginx安装和配置
- nginx的安装和配置
- Educational Codeforces Round 3 C. Load Balancing
- UIScrollView的作用原理,实现scrollView中touch事件作用子视图
- cjson源码剖析(1)
- UIScrollView的delaysContentTouches与canCencelContentTouches属性
- 给键盘添加一个工具条
- nginx安装和配置
- 数据库关于group by 两个或以上条件的分析
- mysql命令一些常用的选项
- poj1815
- JS弹出会话框中文乱码
- txypgx
- vi跳刀最后一行
- POJ 1611 The Suspects
- OC中的容器类及其功能方法:数组,字典,集合