centos下安装nginx
2016-04-21 19:50
676 查看
1、安装nginx
linux环境下安装nginx教程
先获取包wget http://nginx.org/download/nginx-1.8.0.tar.gz 或者http://nginx.org/download/下载最新版
cp nginx-1.8.0.tar.gz /usr/local
cd /usr/local
tar -zxvf nginx-1.8.0.tar.gz
linux环境下安装nginx教程
解压完毕,进去,安装。
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0 \--with-http_ssl_module \--with-http_spdy_module \--with-http_stub_status_module \--with-pcre
执行这个命令
make && make install
之后进入安装目录
然后 启动 ./sbin/nginx
至此 安装完毕了。
修改conf/nginx.conf 来完成配置
启动nginx 服务
./sbin/nginx
重启nginx 服务
./sbin/nginx -s reload/quit
停止nginx 服务
./sbin/nginx -s stop
重新编译文件
./sbin/nginx -t
注:
-t 即为 : test
安装软件包:
./configure --help 查看需要安装的文件
注意:
安装过程过常出现问题:
1、 cc错误: ./configure:error:c compiler cc is not found ---- yum -y install gcc
2、 pcre错误: ./configure:error:the http rewrite module requires the PCRE librery ---- yum -y instanll pcre-decel
3、 openssl错误: ./configure:error:SSL module requires the OPENSSL librery ---- yum -y install openssl-devel
查看状态以及常用命令:
查看运行的状态:ps
anx | grep nginx
ngnix的信号控制:kill -hup 进程号
详细参数:https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/#stopping-or-restarting-nginx
使用自己的域名解析:
vi vi /etc/hosts 增加需要临时映射的域名
2、 nginx.conf 的配置详解
#身份的信息,用什么身份启动NGINX
#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 {
#-- 表示一个进程可运行1024,配置是worker_processes的个数*1024
worker_connections 1024;
}
http {
#文件的类型,doc/text/html
include mime.types;
default_type application/octet-stream;
# 定义Lo的格式
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# 开始使用main
#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;
# 访问的界面,如:www.baidu.com/,及访问的是/
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 的配置
# 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;
# }
#}
}
3、负载均衡
HttpProxyModule 代理模块
HttpUpstreamModule 负载均衡模块
整体思路框架:
nginx.cinf
全局配置
http{
# 服务器的概念
#max_fails=3 fail_timeout=30s weight=2 选填
#max_fail:转换的次数,超出次数则表示服务器挂了
#fail_timeou:超出的时间
#weight:优先级1位最大
#weight
upstream test{
server 192.168.31.187 max_fails=3 fail_timeout=30s weight=2;
server 192.168.31.188;
...
}
server{
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://test;
# 设置调度日志的信息,包括ip时间以及访问的地址
proxy_set_head X-Fowarded_for $remote_addr
}
}
}
参数详解如下:
http://www.cnblogs.com/sunxucool/p/3225818.html http://blog.sina.com.cn/s/blog_59d226590101c9y6.html http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
4、链接服务器的Apache的服务器,tomcat、、、、、
linux环境下安装nginx教程
先获取包wget http://nginx.org/download/nginx-1.8.0.tar.gz 或者http://nginx.org/download/下载最新版
cp nginx-1.8.0.tar.gz /usr/local
cd /usr/local
tar -zxvf nginx-1.8.0.tar.gz
linux环境下安装nginx教程
解压完毕,进去,安装。
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0 \--with-http_ssl_module \--with-http_spdy_module \--with-http_stub_status_module \--with-pcre
执行这个命令
make && make install
之后进入安装目录
然后 启动 ./sbin/nginx
至此 安装完毕了。
修改conf/nginx.conf 来完成配置
启动nginx 服务
./sbin/nginx
重启nginx 服务
./sbin/nginx -s reload/quit
停止nginx 服务
./sbin/nginx -s stop
重新编译文件
./sbin/nginx -t
注:
-t 即为 : test
安装软件包:
./configure --help 查看需要安装的文件
注意:
安装过程过常出现问题:
1、 cc错误: ./configure:error:c compiler cc is not found ---- yum -y install gcc
2、 pcre错误: ./configure:error:the http rewrite module requires the PCRE librery ---- yum -y instanll pcre-decel
3、 openssl错误: ./configure:error:SSL module requires the OPENSSL librery ---- yum -y install openssl-devel
查看状态以及常用命令:
查看运行的状态:ps
anx | grep nginx
-?, -h | Print help. |
-v | Print version. |
-V | Print NGINX version, compiler version and configure parameters. |
-t | Don’t run, just test the configuration file. NGINX checks configuration for correct syntax and then try to open files referred in configuration. |
-q | Suppress non-error messages during configuration testing. |
-s signal | Send signal to a master process: stop, quit, reopen, reload. (version >= 0.7.53) |
-p prefix | Set prefix path (default: /usr/local/nginx/). (version >= 0.7.53) |
-c filename | Specify which configuration file NGINX should use instead of the default. |
-g directives | Set global directives. (version >= 0.7.4) |
TERM, INT | Quick shutdown |
QUIT | Graceful shutdown |
KILL | Halts a stubborn process |
HUP | Configuration reload Start the new worker processes with a new configuration Gracefully shutdown the old worker processes |
USR1 | Reopen the log files |
USR2 | Upgrade Executable on the fly |
WINCH | Gracefully shutdown the worker processes |
使用自己的域名解析:
vi vi /etc/hosts 增加需要临时映射的域名
2、 nginx.conf 的配置详解
#身份的信息,用什么身份启动NGINX
#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 {
#-- 表示一个进程可运行1024,配置是worker_processes的个数*1024
worker_connections 1024;
}
http {
#文件的类型,doc/text/html
include mime.types;
default_type application/octet-stream;
# 定义Lo的格式
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# 开始使用main
#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;
# 访问的界面,如:www.baidu.com/,及访问的是/
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 的配置
# 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;
# }
#}
}
3、负载均衡
HttpProxyModule 代理模块
HttpUpstreamModule 负载均衡模块
整体思路框架:
nginx.cinf
全局配置
http{
# 服务器的概念
#max_fails=3 fail_timeout=30s weight=2 选填
#max_fail:转换的次数,超出次数则表示服务器挂了
#fail_timeou:超出的时间
#weight:优先级1位最大
#weight
upstream test{
server 192.168.31.187 max_fails=3 fail_timeout=30s weight=2;
server 192.168.31.188;
...
}
server{
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://test;
# 设置调度日志的信息,包括ip时间以及访问的地址
proxy_set_head X-Fowarded_for $remote_addr
}
}
}
参数详解如下:
http://www.cnblogs.com/sunxucool/p/3225818.html http://blog.sina.com.cn/s/blog_59d226590101c9y6.html http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
4、链接服务器的Apache的服务器,tomcat、、、、、
相关文章推荐
- Nginx/LVS/HAProxy负载均衡软件对比详解
- nginx lua获取客户端ip
- nginx 502出错集锦
- nginx、php-fpm二三问
- 使用GoAccess分析Nginx日志以及sed/awk手动分析实践
- Nginx 下配置SSL证书的方法
- nginx(Window下安装 & 配置文件参数说明 & 实例)
- Nginx 的启动、停止、平滑重启、信号控制和平滑升级
- 从apache负载均衡到nginx负载均衡
- nginx架构详解
- apache重写规则转Nginx
- nginx 如何限制带宽
- nginx-负载均衡-realIP
- Nginx之ip_hash的hash算法
- Nginx配置文件nginx.conf中文详解
- Nginx 的启动、停止、平滑重启、信号控制和平滑升级
- Nginx Setup CentOS-6.3
- LNMP(linux+nginx+mysql+php)服务器环境配置
- cgi fastcgi wsgi
- Nginx实战系列之功能篇----后端节点健康检查(转)