【安装】Nginx安装
系统平台:CentOS release 6.5 (Final) 64位。
安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
首先要安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
路由重写是Web服务器中的一个很重要的基本功能。通过路由重写,可以结构化URL,更具语义化(对SEO有益)。另外,分享出去的URL可能会因程序路由变动而导致URL失效,而路由的重写可以很好的解决这类问题。
适当的使用Rewrite功能,可以更我们带来很多的好处。Nginx中Rewrite的功能是基于perl语言兼容的正则表达式,所以在编译安装nginx之前,需要安装PREC库。Nginx中Rewrite功能实现是基于ngx_http_rewrite_module,所以确保安装了此模块。
1.下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2.解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
3.进入安装包目录
[root@bogon src]# cd pcre-8.35
4.编译安装
[root@bogon pcre-8.35]# ./configure [root@bogon pcre-8.35]# make && make install
5.查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
安装 Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
2、解压安装包
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
3、进入安装包目录
[root@bogon src]# cd nginx-1.6.2
4、编译安装
[root@bogon nginx-1.6.2]# ./configure --prefix=/opt/module/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/module/pcre-8.35(pcre安装目录) [root@bogon nginx-1.6.2]# make && make install
安装Nginx时报错
./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel
错误提示:
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options.
解决办法:
yum -y install openssl openssl-devel
总结:
yum -y install pcre-devel openssl openssl-devel
5、查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
到此,nginx安装完成。
Nginx 配置
创建 Nginx 运行使用的用户 www:
[root@bogon conf]# /usr/sbin/groupadd www [root@bogon conf]# /usr/sbin/useradd -g www www
配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf
#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; } }
检查配置文件ngnix.conf的正确性命令:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
启动 Nginx
Nginx 启动命令如下:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
如果报错找不到error和access错误日志的路径,则在nginx安装目录下新建一个logs文件夹就可以搞定
访问站点
从浏览器访问我们配置的站点ip:
192.168.0.XXX
Nginx 其他命令
以下包含了 Nginx 常用的几个命令:
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件 /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
修改nginx.conf 并重启
1.把nginx.conf修改为:
#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; pid /usr/local/webserver/nginx/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; # 配置web集群 upstream bakend { #ip_hash; server 192.168.0.204:8080 weight=1; server 192.168.0.170:8080 weight=1; } server { listen 80; server_name localhost; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { #proxy_pass http://192.168.0.170:8080; proxy_pass http://bakend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # location / { #proxy_pass http://192.168.0.170:8080/; proxy_pass http://bakend/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } } }
2.重启Nginx
/usr/local/webserver/nginx/sbin/nginx -s reopen
3. 从浏览器访问我们配置的站点:192.168.0.XXX如下图 部署成功
【安装】Nginx安装的更多相关文章
- CentOS安装Nginx安装详解
一.准备工作,安装依赖包,缺一不可!(推荐先用命令查看自己是否已经安装一下软件,确认没有再安装) --------------------------------------------------- ...
- Linux 安装 nginx 安装PCRE库
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库.这些在执行正规表达式模式匹配时用与Perl 5同样的语法和语义是 ...
- Mac下用brew安装nginx
1. nginx nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TC ...
- git和nginx安装
原始地址: https://www.zybuluo.com/freeethy/note/192109 git安装 设置git的username和email (注册gitlab的账号密码) $$ git ...
- CentOS7.0安装Nginx 1.7.9
一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...
- CentOS 6.5 安装Nginx 1.7.4
一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...
- centos 安装nginx
centos 安装nginx 安装依赖 更换源 yum install http://mirrors.163.com/centos/6.8/extras/x86_64/Packages/epel-re ...
- (转)Centos7 Nginx安装
场景:工作中使用的suse,因为系统可可查资料太少,且系统中一些功能的确实,导致很多集群中功能无法顺利测试通过,在Centos上面进行测试,能够更快的熟悉项目的架构过程! 1 安装准备 首先由于ngi ...
- CentOS7 安装Nginx+MySQL
首先我们需要安装nginx的yum源 [root@AD ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-releas ...
- CentOS7上安装Nginx、PHP、MySQL
一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...
随机推荐
- 自行颁发不受浏览器信任的SSL证书
ssh登陆到服务器上,终端输入以下命令,使用openssl生成RSA密钥及证书. # 生成一个RSA密钥 $ openssl genrsa -des3 -out 33iq.key 1024 # 拷贝一 ...
- 点击TextView 弹出复制选项
extends:http://www.eoeandroid.com/thread-226805-1-1.html package com.dotfive.chuanbang.view; import ...
- html<input>输入框中各种正则表达式设置
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding ...
- apache+tomcat实现session共享
apache+tomcat上篇文章,实现了负载均衡,现在我们实现session共享 一.tomcat集群配置,session 同步配置: tomcat1配置 A.修改Engine节点信息: < ...
- RAID和LVM磁盘阵列
RAID磁盘冗余阵列 CPU的处理性能保持着高速增长,Intel公司在2017年最新发布的i9-7980XE处理器芯片更是达到了18核心36线程.但与此同时,硬盘设备的性能提升却不是很大,因此逐渐成为 ...
- 用Squid实现反向代理
Last-Modified: 告诉反向代理页面什么时间被修改 Expires: 告诉反向代理页面什么时间应该从缓冲区中删除 Cache-Control: 告诉反向代理页面是否应该被缓冲 Pragma: ...
- Oracle数据类型之nchar
nchar(size) nvarchar2(size) n 代表的意思是编码格式为unicode编码,无论中文或者英文都以一个字符来存放数据. 举例: 比如“a” ,占用一个字符 比如“月”,占用一 ...
- poj2376 Cleaning Shifts【线段树】【DP】
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32561 Accepted: 7972 ...
- C#实现像Git那样计算Hash值
从Git Tip of the Week: Objects一文中得知,Git是这样计算提交内容的Hash值的: Hash算法用的是SHA1 计算前,会在内容前面添加"blob 内容长度\0& ...
- 集成tomcat插件到eclipse
Eclipse中Tomcat的配置及简单例子 环境: 系统: Windows 7 64位专业版 Eclipse: Eclipse Java EE IDE for Web Developers. ...