Linux安装nginx
2016-01-04 14:07
603 查看
下载压缩包
wget http://nginx.org/download/nginx-1.6.3.tar.gz[/code]
解压tar -zxvf nginx-1.6.3.tar.gz
安装配置(这里默认)./configure
这里一般会有几个依赖错误:./configure: error: the HTTP gzip module requires the zlib libraryyum install zlib-devel./configure: error: C compiler cc is not foundyum -y install gcc./configure: error: the HTTP rewrite module requires the PCRE libraryyum install pcre-devel
再次执行./configure
出现如下就ok了Configuration summary + using system PCRE library + OpenSSL library is not used + using builtin md5 code + sha1 library is not found + using system zlib library
可以看到OpenSSL和sha1未找到,这里可以不用管,但如果想用其功能可以安装对应的依赖yum install openssl openssl-devel yum install perl-Digest-SHA1.x86_64 ./configure --with-http_stub_status_module --with-http_ssl_module
编译 安装make && make install
默认目录cd /usr/local/nginx/
可以加到环境变量中:vim /etc/profile export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin source /etc/profile
测试下nginx -v
配置文件 默认路径(/usr/local/nginx/conf/)#Nginx所用用户和组,window下不指定 #user niumd niumd; #工作的子进程数量(通常等于CPU数量或者2倍于CPU) worker_processes 2; #错误日志存放路径 #error_log logs/error.log; #error_log logs/error.log notice; error_log logs/error.log info; #指定pid存放文件 pid logs/nginx.pid; events { #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。 #use epoll; #允许最大连接数 worker_connections 2048; } http { include mime.types; default_type application/octet-stream; #定义日志格式 #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 off; access_log logs/access.log; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; client_header_buffer_size 1k; large_client_header_buffers 4 4k; sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 75 20; proxy_next_upstream off; #include gzip.conf; upstream localhost { #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能,需要通过缓存进行共享解决。 #同一机器在多网情况下,路由切换,ip可能不同 ip_hash; server localhost:8090; } server { listen 8080; server_name 127.0.0.1; #这里设置域名或者请求ip location / { proxy_connect_timeout 30; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost; } #静态文件访问 location ~ ^/(upload|static)/ { root /data/www; expires 2d; } } }
检查配置文件是否正确nginx -t
启动nginx
重启nginx -s reload
关闭可以直接kill掉进程ps -ef | grep nginx kill -9 nginx
相关文章推荐
- nginx源码剖析(1)----概要
- nginx源码学习----内存池
- nginx中配置跨域支持功能
- Linux上安装Nginx
- 使用gdb调试nginx源码
- Nginx reopen reload作用及工作过程
- nginx+rtmp子进程管理不当导致频繁的deleteStream(未断开连接)
- 配置ab来为Nginx服务器做压力测试的方法
- nginx代理
- OpenResty(Nginx)+Lua+GraphicsMagick实现缩略图功能
- CentOS7安装Nginx-1.9.9+PHP5.6
- nginx之深坑
- 隐藏Nginx或Apache以及PHP的版本号的方法
- fastdfs nginx 配置片段
- apache与nginx的默认虚拟主机的配置及作用
- CentOS 7中 安装nginx服务器
- 解决Nginx+PHP-FPM出现502(Bad Gateway)错误问题
- CentOS7 YUM 安装NGINX
- linux下nginx的安装
- Nginx服务器下配置个性二级域名及多个域名的实例讲解