Linux下安装Nginx详细步骤及nginx多服务器配置
2016-12-21 10:51
1161 查看
什么是Nginx?
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。
Nginx 作为 负载均衡 服务器:
Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器:
Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。
Nginx的安装
模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
Nginx包下载: http://nginx.org/en/download.html
依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
图解教程
第一步: 下载安装所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.2.6.tar.gz
第二步:依次安装openssl-fips-2.0.2.tar.gz, zlib-1.2.7.tar.gz, pcre-8.21.tar.gz, nginx-1.2.6.tar.gz
1.安装openssl-fips-2.0.2.tar.gz
2.安装zlib-1.2.7.tar.gz
3.安装pcre-8.21.tar.gz
4.安装 nginx-1.2.6.tar.gz
至此Nginx的安装完成!
第三步:检测是否安装成功
出现如下所示提示,表示安装成功
启动nginx
查看端口
结果如下
nginx.conf文件配置 以下内容全部复制然后修改对应域名和IP与端口就能通用,修改配置文件后重启nginx #/usr/local/nginx/sbin ./nginx -s reload
#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;
#内网分流IP与端口
upstream web-server {
ip_hash;
server 192.168.1.114:8081;
}
upstream web-server-8080 {
ip_hash;
server 192.168.1.114:8080;
}
upstream web-server-wei{
ip_hash;
server 192.168.1.129:8080;
}
#linux服务器-外网映射 80端口
server {
listen 80;
server_name deve.yumeitech.net;
#charset koi8-r;
#access_log logs/host.access.log main;
#对应分流IP与项目名称
location /cashier/ {
proxy_pass http://web-server;
}
location /paydemo/ {
proxy_pass http://web-server-8080; }
location /xw/ {
proxy_pass http://web-server-wei;
}
#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 ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。
Nginx 作为 负载均衡 服务器:
Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器:
Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。
Nginx的安装
模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
Nginx包下载: http://nginx.org/en/download.html
依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
图解教程
第一步: 下载安装所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.2.6.tar.gz
第二步:依次安装openssl-fips-2.0.2.tar.gz, zlib-1.2.7.tar.gz, pcre-8.21.tar.gz, nginx-1.2.6.tar.gz
1.安装openssl-fips-2.0.2.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz [root@localhost mrms]# cd openssl-fips-2.0.2 [root@localhost openssl-fips-2.0.2]# ./config [root@localhost openssl-fips-2.0.2]# make [root@localhost openssl-fips-2.0.2]# make install
2.安装zlib-1.2.7.tar.gz
[root@localhost mrms]# tar -zxvf zlib-1.2.7.tar.gz [root@localhost mrms]# cd zlib-1.2.7 [root@localhost zlib-1.2.7]# ./configure [root@localhost zlib-1.2.7]# make [root@localhost zlib-1.2.7]# make install
3.安装pcre-8.21.tar.gz
[root@localhost mrms]# tar -zxvf pcre-8.21.tar.gz [root@localhost mrms]# cd pcre-8.21 [root@localhost pcre-8.21]# ./configure [root@localhost pcre-8.21]# make [root@localhost pcre-8.21]# make install
4.安装 nginx-1.2.6.tar.gz
[root@localhost mrms]# tar -zxvf nginx-1.2.6.tar.gz [root@localhost mrms]# cd nginx-1.2.6 [root@localhost nginx-1.2.6]# ./configure --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2 [root@localhost nginx-1.2.6]# make [root@localhost nginx-1.2.6]# make install
至此Nginx的安装完成!
第三步:检测是否安装成功
[root@localhost nginx-1.2.6]# cd /usr/local/nginx/sbin [root@localhost sbin]# ./nginx -t
出现如下所示提示,表示安装成功
启动nginx
[root@localhost sbin]# ./nginx
查看端口
[root@localhost sbin]# netstat -ntlp
结果如下
nginx.conf文件配置 以下内容全部复制然后修改对应域名和IP与端口就能通用,修改配置文件后重启nginx #/usr/local/nginx/sbin ./nginx -s reload
#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;
#内网分流IP与端口
upstream web-server {
ip_hash;
server 192.168.1.114:8081;
}
upstream web-server-8080 {
ip_hash;
server 192.168.1.114:8080;
}
upstream web-server-wei{
ip_hash;
server 192.168.1.129:8080;
}
#linux服务器-外网映射 80端口
server {
listen 80;
server_name deve.yumeitech.net;
#charset koi8-r;
#access_log logs/host.access.log main;
#对应分流IP与项目名称
location /cashier/ {
proxy_pass http://web-server;
}
location /paydemo/ {
proxy_pass http://web-server-8080; }
location /xw/ {
proxy_pass http://web-server-wei;
}
#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;
# }
#}
}
相关文章推荐
- linux下lighttpd服务器的详细安装步骤 以及对flv流媒体的支持配置
- Linux上安装搭建Nginx服务器的详细步骤
- Linux下从零开始安装配置Nginx服务器+PHP开发环境
- 【原创】linux下安装配置JDK+tomcat+mysql详细步骤
- linux下安装nginx详细步骤
- nginx高并发服务器配置及linux内核优化参数详细说明
- 虚拟机Linux系统安装nginx服务器并启动的步骤
- 安装和配置CentOS服务器的详细步骤
- Linux 安装nginx服务器详细介绍
- Linux中安装配置hadoop集群详细步骤
- Linux搭建TortoiseSVN服务器安装步骤及配置
- Linux下从零开始安装配置Nginx服务器+PHP开发环境
- centos 5 yum安装与配置vsFTPd FTP服务器详细步骤
- centos 5 yum安装与配置vsFTPd FTP服务器详细步骤
- Linux下源码安装nginx服务器以及部分配置
- 高性能web服务器(热死你)Resin Linux的安装、配置、部署,性能远超Nginx支持Java、PHP等
- 安装linux学习六(4):Nginx配置文件详细说明
- 在linux系统用命令行下载、安装和配置jdk1.8的详细步骤(以CentOS为例)
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
- 在linux系统中安装mysql服务器详细步骤并解决ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw