nginx
来源:互联网 发布:linux ftp的宿主 编辑:程序博客网 时间:2024/05/30 02:23
环境
centerOS 7
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_realip_module
make && make install
测试 /usr/local/nginx/sbin/nginx
例:./configure –prefix=/usr/local/nginx-1.6 –with-pcre \
–with-http_stub_status_module –with-http_ssl_module \
–with-http_gzip_static_module –with-http_realip_module \
–add-module=../nginx_upstream_check_module-0.3.0
nginx大部分常用模块,编译时./configure –help以–without开头的都默认安装。
–prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
–conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
–user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。–group=name类似
–with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
–with-zlib=PATH : 指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
–with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
–with-http_stub_status_module : 用来监控 Nginx 的当前状态
–with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
–add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)
配置 nginx.cnf
`user root;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
pid /usr/local/nginx/nginx.pid;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
log_format main ‘
‘
\#access_log logs/access.log main; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_body_buffer_size 8m; #256k # server_tokens off; ignore_invalid_headers on; recursive_error_pages on; server_name_in_redirect off;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;gzip on; tcp_nopush on; tcp_nodelay on; #proxy options proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 64k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_next_upstream error timeout invalid_header http_500; #proxy_next_upstream_tries 3; #size limits client_max_body_size 50m; 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; proxy_temp_path /dev/shm/proxy_temp; fastcgi_temp_path /dev/shm/fastcgi_temp; client_body_temp_path /dev/shm/client_body_temp; include vhosts/*.conf;
}`
在conf目录创建 vhosts目录
增加节点配置文件如
`server {
listen 80;
server_name i.image.com;
access_log /var/log/nginx/access.log ;
error_log /var/log/nginx/error.log;
proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 64k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; location / { root /data; expires 7d; } #location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { #root /data/static; # expires 7d; #}
}`
或
upstream web{
server 127.0.0.1:10004;
#server ;
}
server {
listen 80;
server_name www.xx.com;
access_log /var/log/nginx/access.log ;
error_log /var/log/nginx/error.log;
proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 64k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://web; break; } location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /opt/webapp/trade-web; #expires 7d; }
}
/usr/local/nginx/sbin/nginx -t 检查
/usr/local/nginx/sbin/nginx -V 显示编译参数
./sbin/nginx -s stop 或 pkill nginx
重启,不会改变启动时指定的配置文件
./sbin/nginx -s reload
或 kill -HUP cat /usr/local/nginx-1.6/logs/nginx.pid
- nginx
- Nginx
- Nginx
- Nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- [自然语言处理] 在NLP的路上越走越远(自然语言处理各类资源wiki)
- eclipse下载
- Prim算法和Kruskal算法的基本思想和实现
- Qt中的析构函数
- java中的全局变量与局部变量
- nginx
- Android 读取文件File的大小
- Android 5.1 SystemUi 之 StatusBar的简单分析
- Python装饰器为什么难理解?
- FPGA的LPM标准
- Linux 使用pwgen命令创建随机密码
- YII2框架学习 扩展篇(三) Mixin技术
- 删除文件
- Kafka2.10<使用JavaAPI 批量发送生产数据>