1.nginx安装和配置
1.安装
1.1安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel wget
1.2安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址: http://ftp.pcre.org/pub/pcre/pcre-8.35.tar.gz
cd /usr/local/src/ wget http://ftp.pcre.org/pub/pcre/pcre-8.35.tar.gz
2、解压安装包:
tar zxvf pcre-8.35.tar.gz
3、进入安装包目录
cd pcre-8.35
4、编译安装
./configure make && make install
5、查看pcre版本
pcre-config --version
1.3安装Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.14.2.tar.gz
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.14.2.tar.gz
2、解开安装包
tar zxvf nginx-.tar.gz
3、进入安装包目录
cd /usr/local/src/nginx-
4、编译安装
编译参数视使用场景而定,这里需要使用tcp负载均衡 所以编译了stream模块
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --with-stream make make install
5、加入环境变量
vim /etc/profile 在后面导入nginx的安装路径 export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin 刷新配置source /etc/profile
6、查看nginx版本
查看版本: nginx -v 查看详细信息: nginx -V
2.配置Nginx
1、配置文件路径
/usr/local/nginx/conf/nginx.conf
2、配置文件样例(为方便编辑,可用xftp下载下来配置好后传上去)
user nginx;
worker_processes ;
error_log /usr/local/nginx/logs/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections ;
}
http {
include /usr/local/nginx/conf/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 /usr/local/nginx/logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout ;
#gzip on;
upstream honeysuckle {
ip_hash;
server ;
server ;
server ;
}
server{
listen ;
location / {
proxy_pass http://honeysuckle;
}
}
upstream rabbitmqweb {
ip_hash;
server ;
server ;
server ;
}
server{
listen ;
location / {
proxy_pass http://rabbitmqweb;
}
}
include /etc/nginx/conf.d/*.conf;
}
stream{
upstream rabbitmq{
server 192.168.161.200:5672 weight=1;
server 192.168.161.201:5672 weight=1;
server 192.168.161.202:5672 weight=1;
}
server{
listen 5672;
proxy_pass rabbitmq;
}
}
3、添加nginx用户组
说明:如不添加在启动时会提示 getpwnam("nginx") failed 检查配置文件也不会通过
这里创建的用户是你安装Nginx时,预编译时指定的Nginx用户(1.3 第四条的编译参数)
useradd nginx -s /sbin/nologin -M
4、测试配置文件的正确性
nginx -t 返回如下信息,表示配置文件语法正确 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
3.配置开机启动
1.1 进入到/lib/systemd/system/目录
cd /lib/systemd/system/
1.2 创建nginx.service文件,并编辑
vim nginx.service
[Unit] Description=nginx service After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
1.3设置启用开机启动和禁止开机启动
systemctl enable nginx systemctl disable nginx
1.4 其他常用命令
systemctl start nginx.service 启动nginx服务 systemctl stop nginx.service 停止服务 systemctl restart nginx.service 重新启动服务 systemctl list-units --type=service 查看所有已启动的服务 systemctl status nginx.service 查看服务当前状态 systemctl enable nginx.service 设置开机自启动 systemctl disable nginx.service 停止开机自启动
4.常见问题
1.1 open() "/var/run/nginx.pid" failed (2: No such file or directory)
sudo nginx -c /etc/nginx/nginx.conf nginx -s reload
1.2 查看已经安装的模块
[root@loadbalancing ~]# nginx -V nginx version: nginx/ built by gcc (Red Hat -) (GCC) built with OpenSSL Jan TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
1.nginx安装和配置的更多相关文章
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...
- ubuntu server nginx 安装与配置
ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...
- Nginx安装及配置详解【转】
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html
Nginx安装及配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- centos7系统下nginx安装并配置开机自启动操作
准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...
- linux nginx安装以及配置
一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- Nginx安装以及配置
安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...
- Nginx安装与配置-Centos7
Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...
- LVS+Nginx(LVS + Keepalived + Nginx安装及配置)
(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...
随机推荐
- ASP.NET框架获取数据字典数据做成树的格式
private List<TreeEntity> treeList = new List<TreeEntity>();//创建一个树的List集合 public ActionR ...
- shell 字符串中定位字符位置 获取字符位置
linux shell 字符串操作(长度,查找,替换)详解 该博文中描述的如下两个字符串操作, ${string:position} #在$string中, 从位置$position开始提取子串 ${ ...
- HTML5 Canvas核心技术:图形、动画与游戏开发 PDF扫描版
HTML5 Canvas核心技术:图形.动画与游戏开发 内容简介: <HTML5 Canvas核心技术:图形.动画与游戏开发>中,畅销书作家David Geary(基瑞)先生以实用的范例程 ...
- C# 文本输入限制类型,datagridview单元格输入验证
1.只能输入double类型 private void textBoxX6_KeyPress(object sender, KeyPressEventArgs e) { { //数字0~9所对应的ke ...
- DDD模式
http://www.cnblogs.com/landeanfen/p/4816706.html https://www.cnblogs.com/malaoko/p/8732552.html
- .Net 项目代码风格规范
最近没啥时间自己状态也不是很好,公司的事情忙,自己也有一些事情要处理,所以好久没有写博客了.利用公司午休时间写一写,以下是参考了一些资料,整理出来,共勉之. 代码风格没有正确与否,重要的是整齐划一,清 ...
- 《C#多线程编程实战》2.7 CountDownEvent
这个同步线程的类大概是东北的. 很有意思. 会限定你的线程使用的次数,更形象一点的像是你妈,提前准备好你要使用的线程的次数,用不完还不高兴那种的. 使用顺序基本就是 实例化 填充线程的启动次数 使用 ...
- day01.1-Python编译器的安装
一. 在Windows环境中安装Python编译器 1. 访问Python官网https://www.python.org,下载适用于Windows环境的相关编译器版本: 2. 点击Pytho ...
- 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例
根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...
- cookie,session 的概念以及在django中的用法,以及cbv装饰器用法
cookie的由来: 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不会直接影响后 ...