nginx安装配置
来源:互联网 发布:怎样制作炒股票软件 编辑:程序博客网 时间:2024/06/04 18:51
1、为什么选择nginx
Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应,感谢 Nginx 为我们选择了 epoll and kqueue 作为开发模型.
作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。
作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件 非常简洁(还能够支持perl语法),Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。
2、安装nginx
ngnix依赖以下模块
gzip模块需要zlib库
rewrit模块需要pcre库
ssl功能需要openssl库
1、安装pcre
获取pcre编译安装包,在可以在 http://www.pcre.org/ 点击download获取,地址为 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 我下载的prce-8.37.tar.gz
解压tar包 ,我这里放入到根目录下的soft目录里
lin@ubuntu:/soft$ ls
jdk1.7.0_79 jdk-7u79-linux-x64.tar.gz pcre-8.37.tar.gz
lin@ubuntu:/soft$ tar -zxvf pcre-8.37.tar.gz
进入解压缩目录,执行./configure。
lin@ubuntu:/soft/pcre-8.37$ ./configure
make & make install
lin@ubuntu:/soft/pcre-8.37$ make
lin@ubuntu:/soft/pcre-8.37$ sudo make install
2、安装openssl
获取openssl编译安装包,在http://www.openssl.org/source/ 上可以获取当前最新的版本。我使用的是openssl-1.0.0t.tar.gz版本
解压tar包 ,我这里放入到根目录下的soft目录里
lin@ubuntu:/soft$ tar -zxvf openssl-1.0.0t.tar.gz
进入解压缩目录,执行./config。
lin@ubuntu:/soft/openssl-1.0.0t$ ./config
make & make install
lin@ubuntu:/soft/openssl-1.0.0t$ make
lin@ubuntu:/soft/openssl-1.0.0t$ sudo make install
3、安装zlib
获取zlib编译安装包,在http://www.zlib.net/ 上可以获取当前最新的版本。我使用的是zlib-1.2.8.tar.gz版本
解压缩tar.gz包 我的是放入根目录soft里面。
lin@ubuntu:/soft$
tar -xf zlib-1.2.8.tar.gz
进入解压缩目录,执行./configure。
lin@ubuntu:/soft/zlib-1.2.8$ ./configure
make & make install
lin@ubuntu:/soft/
zlib
-
1.2.8
$ make
lin@ubuntu:/soft/
zlib
-
1.2.8
$ sudo make install
4、安装nginx
获取nginx,在http://nginx.org/en/download.html 上可以获取当前最新的版本。我使用的是nginx-1.8.0.tar.gz版本
解压缩tar.gz包,我的放入到根目录下的soft里面。
lin@ubuntu:/soft$ tar -zxvf nginx-1.8.0.tar.gz
进入解压缩目录,执行./configure
lin@ubuntu:/soft/nginx-1.8.0$ ./configure
make & make install
lin@ubuntu:/soft/nginx-1.8.0$ make
lin@ubuntu:/soft/nginx-1.8.0$ sudo make install
到此安装完毕,环境准备结束
3、简单启动nginx
由于nginx占用的是80端口,所以先确保系统的80端口没有被其他程序占用
1、启动nginx
lin@ubuntu:/usr/local/nginx$ sudo sbin/nginx
2、检查是否启动成功
netstat -ano|grep 80
有输出就证明启动成功
3、访问80端口,打开浏览器输入nginx所在的电脑ip出现 Welcome to nginx! 则证明成功!
像重启的话 可以用
lin@ubuntu:/usr/local/nginx$ sudo sbin/nginx -s reload
4、停止服务可以用
lin@ubuntu:/usr/local/nginx$ sudo killall nginx
4、nginx配置
安装完成后,配置目录conf下有很多配置文件,其中除了nginx.conf,其余的配置文件,使用默认提供的即可。
nginx.conf是主配置文件其中
work_process 表示工作进程的数量,一般设置为cpu的核数。
worker_connections 表示每个工作进程的最大连接数
server{}定义了虚拟机主机
listen 监听端口;
server_name 监听域名
location/{} 是用来为匹配的 URI 进行配置,URI 即语法中的“/uri/”。
location / { }匹配任何查询,因为所有请求都以 / 开头。
root指定对应uri的资源查找路径,这里html为相对路径,完整路径为/opt/ opt/nginx-1.7.7/html/
index指定首页index文件的名称,可以配置多个,以空格分开。如有多个,按配置顺序查找。
下面是默认配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
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;
#}
# 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;
#}
}
# 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;
# }
#}
}
很容易看出来 nginx监听了80端口,域名为loccalhost,根路径为html文件夹,默认文件为index.html,index.htm,服务器错误重定向到50x.html
可以看到nginx html文件夹下面有如下文件
lin@ubuntu:/usr/local/nginx$ cd html
lin@ubuntu:/usr/local/nginx/html$ ls
50x.html index.html
这就是刚刚上面所说的启动nginx时候访问的页面,其实就是这里的index.html页面
- centos 安装nginx 配置nginx
- Nginx 安装配置
- nginx安装与配置
- Nginx的安装配置
- Nginx安装配置
- nginx 安装,配置
- nginx 安装及配置
- Nginx安装与配置
- Nginx基本安装配置
- nginx安装与配置
- 安装 配置 Nginx
- Nginx安装配置备忘
- awstats+nginx 安装配置
- Nginx 安装与配置
- nginx安装配置
- nginx 安装与配置
- nginx安装和配置
- nginx安装配置
- 使用JQuery UI完成可输入内容且自动匹配的的下拉列表
- linux 下批量kill 同名进程的方法
- qt tableview代理实现
- 技术分享-在安卓APP上完成手机号码确认的新技术,对短信资费敏感的同学请重点关注
- web_css:inline-block
- nginx安装配置
- vmware下安装Archlinux遇到的问题记录
- blueimp/jquery-File-Upload中文文档
- Java---微信公众号开发
- php
- 常见汇编代码
- 软件测试 (一) 软件测试方法大汇总
- 数据类型的位数
- 网络编程 java