一安装ngnix
好不容易在wps做出来的文档图片粘贴不出来,我也是日了狗了,后续会补回来的,其实网上面的教程很多,也都是正确的,但是不是缺少这一步就是缺少那一步,菜鸟教程的也不完整,所以博主一步一步的查资料整理了这篇教程,包括一些依赖库的用法。希望对大家有用。先lol先。觉得博主写的好的,博主后续在增加php,redis,memcache,mysql安装教程,也是尽量的写详细,把各种坑都写出来给大家看看。
一:yum安装:
最简单的安装方式,查看源是否有安装包:yum search ngnix,一般情况下给系统安装阿里云,网易云以及epel源基本上所有的安装包都能找得到
yum search nginx
yum install -y nginx
二:编译安装】
参考资料:http://www.runoob.com/linux/nginx-install-setup.html
1安装相关依赖库,编译环境:
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
具体每个依赖库的作用我们后续再说,现在先一步步安装下去
直接安装开发者基本工具 yum -y groupinstall “ Development Tools”
2安装pcre
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
3、解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
4、进入安装包目录
[root@bogon src]# cd pcre-8.35
5、编译安装
[root@bogon pcre-8.35]# ./configure[root@bogon pcre-8.35]# make && make install
6、查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
7 查看pcre安装位置
pcre-config --prefix
安装nginx
- 获取安装包
[root@localhost package]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
- 解压
[root@localhost package]# tar zxvf nginx-1.6.2.tar.gz
3进入安装包
[root@localhost package]# cd nginx-1.6.2
包里面的内容
4 ./configure
检测安装系统环境并且配置参数
./configure各参数详解
参考资料:http://www.cnblogs.com/milkone/p/9361192.html
其中几个重要参数:
--prefix=/usr/local/nginx-1.3.1 有利于统一放置nginx的所有文件,方便管理,强烈建议设置
--with-http_stub_status_module 支持统计,也有利于监控系统用来监控nginx的性能
--with-http_ssl_module 支持ssl加密
--with-pcre=/xx/pcre-xx 必要条件
--with-pcre=DIR 指定PCRE库源码位置;此处注意值得是源码位置,切不可制定到安装位置。
本教程pcre源码为其他位置/xxx/package/pcre-8.35
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/xxx/package/pcre-8.35
编译结果:
Configuration summary
+ using PCRE library: /home/newbrash_linux/package/pcre-8.35
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/webserver/nginx"//安装位置
nginx binary file: "/usr/local/webserver/nginx/sbin/nginx"//二进制库位置,即启动程序等所在的位置
nginx configuration prefix: "/usr/local/webserver/nginx/conf"
nginx configuration file: "/usr/local/webserver/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/webserver/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/webserver/nginx/logs/error.log"
nginx http access log file: "/usr/local/webserver/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
2 make
编译生成目标文件以及.lo,.la等文件
3 make install
把编译生成的文件安装到配置的位置
4 配置环境变量以及开机启动
文件配置目录为/etc
环境变量文件 profile
启动文件为: rc.local
查看环境变量文件:vim /etc/profile
第一句话的意思是:全局环境跟启动程序,没错了就是这个文件
在export PATH位置下面添加下面这句话
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
export PATH=/usr/local/webserver/nginx/sbin:$PATH
接着重新执行一次环境变量文件
验证命令是否起作用:
nginx -v
此时就有大佬看出来了,我配置nginx环境变量虽然成功了,但是其它环境变量被我搞没了,想重新改回去发现vi指令用不了
一看环境变量只有一个
此时我们可以使用其它方法给文本追加内容
//echo后边用单引号包围要添加的内容
echo export PATH=/usr/local/webserver/nginx/sbin:/usr/bin:/usr/sbin:/usr>>/etc/profile
这时候同学们注意千万不要使用一个>
5 添加用户组以及用户
groupadd www
useradd www www
6 修改配置文件
配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf
user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events{
use epoll;
worker_connections 65535;}
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';
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
{
listen 80;#监听端口
server_name localhost;#域名
index index.html index.htm index.php;
root /usr/local/webserver/nginx/html;#站点目录
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
}
检查配置文件nginx.conf的正确性命令:
[root@localhost conf]# nginx -t
7启动
[root@localhost conf]# nginx
8访问站点
Ifconfig查看域名
直接使用域名访问
这里有一点需要注意,配置文件里使用的是80端口,我们需要开发80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙:
systemctl restart firewalld