Nginx(一)

本文详细介绍了Nginx的定义、安装过程及启动方法。Nginx是一款高性能的HTTP服务器,支持负载均衡和邮件服务。文章涵盖从下载、用户创建、文件解压到配置与启动的全过程,并解决常见问题。

一、什么是 nginx?

     nginx是一种高性能的HTTP和反向代理服务器 ,同时也是一个代理邮件服务器,我们在nginx上可以发布网站,也可以实现负载均衡的功能 ,还可以作为邮件服务器实现收发邮件等功能 。所谓负载均衡是指当同时有多个用户访问服务器的时候,为了减轻服务器压力,我们需要将用户分别引入各服务器,分担服务器的压力。

  nginx 可以实现高并发、部署简单、 内存消耗少、成本低等优点。

二、nginx安装

    下载地址: http://nginx.org/en/download.html

下载完后,将软件包上传到linux指定目录(也可以使用 wget下载,如

      wget http://nginx.org/download/nginx-1.10.3.tar.gz):

[root@huangkai200 src]# pwd
/usr/src
[root@huangkai200 src]# ll
total 910812
-rw-r--r--. 1 root root     910812 Dec 24 21:45 nginx-1.10.2.tar.gz
[root@huangkai200 src]# 

添加用户  useradd nginx -s /sbin/nologin -M # -s 表示指定用户登陆所使用的 shell,nologin表示此用户不能登陆 -M 表示不创建用户home目录

解压文件 : tar -zxvf nginx-1.10.3.tar.gz

./configure --user=nginx --group=nginx --prefix=/usr/local/soft/nginx --with-http_stub_status_module --with-http_ssl_module

  --user 指定用户

--group  指定组

--prefix 指定安装路径

--with-http_stub_status_model    激活状态信息

--with-http_ssl_module      激活SSL功能    

make 

makeinstall

在安装过程中,可能会遇到一些错误

 nginx 安装需要 openssl、gcc、pcre  的支持

可执行 yum install openssl openssl-devel -y 安装

yum install pcre pcre-devel gcc-c++ -y

 

三 、启动nginx

[huangkai@huangkai200 sbin]$ pwd
/usr/local/soft/nginx/sbin
[huangkai@huangkai200 sbin]$ ./nginx -t  # 检查nginx 配置是否成功
nginx: the configuration file /usr/local/soft/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
nginx: configuration file /usr/local/soft/nginx/conf/nginx.conf test failed
[huangkai@huangkai200 sbin]$ 

如果出现上面的错误信息 ,nginx 默认端口号为 80 ,在 linux中,默认 0 —— 1024 号端口需要 root用户才能启动,所以需要切换到 root用户,或者更改nginx 默认端口号。

[huangkai@huangkai200 sbin]$ su - root  # 切换到root用户
Password: 
Last login: Sat Mar 18 15:02:28 CST 2017 on pts/0
[root@huangkai200 ~]# cd /usr/local/soft/nginx/
[root@huangkai200 nginx]# ./sbin/nginx -t # 检查nginx 配置
nginx: the configuration file /usr/local/soft/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/soft/nginx/conf/nginx.conf test is successful
[root@huangkai200 nginx]#

启动nginx 

[root@huangkai200 nginx]# ./sbin/nginx 
[root@huangkai200 nginx]# ps -ef|grep ngin
gdm       1338  1218  0 13:21 ?        00:00:00 /usr/libexec/ibus-engine-simple
root      6597     1  0 15:20 ?        00:00:00 nginx: master process ./sbin/nginx
nginx     6598  6597  0 15:20 ?        00:00:00 nginx: worker process
root      6610  6474  0 15:20 pts/0    00:00:00 grep --color=auto ngin
[root@huangkai200 nginx]# 

如上,表示 nginx 启动成功,可以使用浏览器访问 http://192.168.1.200/

 

nginx 平滑启动: 进入 ${nginx}/sbin目录 , ./sbin nginx -s reload ,平滑启动必须是nginx已运行状态

nginx 停止     ./sbin/nginx stop

转载于:https://my.oschina.net/hkai/blog/861931

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值