关于nginx启动报错,请问统信这服1务1器的操作系统linux怎么启动nginx服务解决?

第一部分:Nginx基础1. Nginx概述以及作用Nginx同Apache,Tomcat一样,是一种服务器软件.他是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP代理服务器.因此,使用Nginx可以搭建网站,也可以实现负载均衡的功能,还可以作为邮件服务器来接受和发送邮件.Nginx1.9.0之后还可以作为通用的TCP/UDP代理服务器,也可以提供一定的缓存服务功能.1.1 可以作为Web服务器Nginx还是一个高性能的HTTP Web服务器(Web服务器还有Apache, IIS),它可以提供基本的HTTP功能和扩展功能,可以先通过动态/静态内容分离,而后为静态内容(Http/CSS/JS/甚至是资源服务器目录内容)提供HTTP访问功能;而动态内容可以整合代理模块,代理给上游服务器,以支持对外部程序的直接调用或者解析,如FASTCGI支持PHP1.2作为反向代理服务器反向代理服务器作用在服务器端,他在服务器端接收互联网中的链接请求,然后将请求转发给内部网络中的服务器,并且将从服务器中得到的结果返回给互联网中请求连接的客户端,如图所示反向代理服务器对外是透明的,在客户端不需要任何的配置,所以访问者并不知道自己访问的是一个反向代理服务器,Nginx就是一个反向代理服务器反向代理服务器针对Web服务器提供加速的功能,所有的外部网络要访问服务器的请求都要通过他.反向代理服务器负责接受客户端的请求,然后到资源服务器上获取内容,把内容返回给用户,并且把内容保存在在本地中,以便在日后收到同样的信息请求时可以把本地缓存中的内容直接发给用户,以减少后端Web的压力,提高响应速度,因此,Nginx还具有缓存功能.1.3 反向代理服务器实现负载均衡Nginx可以通过反向代理服务器实现负载均衡,以优化网站的负载,如图1.4 可以作为邮件代理服务器2. 为什么选择NginxNginx有着高并发,性能好和占用内存少等特点,其安装简单,配合文件简介,启动容易,能够长时间运行,还可以在不间断服务的情况下升级软件版本,而且成本低,这些优点使得Nginx的应用越来越普遍2.1 高并发,性能好,占用内存少和稳定作为Web服务器,相比Apache,Nginx占用内存更少,支持的并发连接更多,使用效率更高,并且Nginx要比Apache更"轻量",性能更好2.2 功能强大可以作为Web服务器,反向代理服务器,也可以作为邮件服务器2.3 扩展化高Nginx的模块化设计极具扩展性,这种低耦合的配置,使得Nginx拥有数量庞大的第三方模块.当然那这些公开的模块和官方模块一样好用2.4 其他优点跨平台,占用内存小,配置操作简单,支持内置服务器检测3. 安装NginxNginx可以在不同的操作系统安装.本节在Centos7.x操作系统为例,介绍Nginx的安装和相关配置注意:一定要选择root用户开发,sudo也不行1. 准备工作安装依赖包 gcc,g++yum -y install gcc
yum -y install g++
安装必要的库:zlib,pcree,opensslpcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库yum install -y pcre pcre-devel
zlib库提供了很多中解压和压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要安装yum install -y zlib zlib-devel
openssl是web安全通信的基础yum install -y openssl openssl-devel
2. 下载解压下载nginx安装包wget http://nginx.org/download/nginx-1.9.9.tar.gz
解压到/usr/local/softwaretar -zxvf
nginx-1.9.9.tar.gz -C /usr/local/software
3. 配置使用configure命令进行配置.他定义了系统的各个方面配置,包括Nginx允许用于连接处理的方法,并且最终创建一个MakeFile文件其中./confgiure --help可以列出大部分的模块和编译选项,其中以without开头都是默认安装,以PATH结尾的选项需要手动指定依赖库源码目录[lidengyin@ldy nginx-1.9.9]$ ./configure --help
--help
print this message
--prefix=PATH
set installation prefix
--sbin-path=PATH
set nginx binary pathname
--conf-path=PATH
set nginx.conf pathname
--error-log-path=PATH
set error log pathname
--pid-path=PATH
set nginx.pid pathname
--lock-path=PATH
set nginx.lock pathname
--user=USER
set non-privileged user for
worker processes
--group=GROUP
set non-privileged group for
worker processes
--build=NAME
set build name
--builddir=DIR
set build directory
--with-select_module
enable select module
--without-select_module
disable select module
--with-poll_module
enable poll module
--without-poll_module
disable poll module
--with-threads
enable thread pool support
--with-file-aio
enable file AIO support
--with-ipv6
enable IPv6 support
--with-http_ssl_module
enable ngx_http_ssl_module
--with-http_v2_module
enable ngx_http_v2_module
--with-http_realip_module
enable ngx_http_realip_module
--with-http_addition_module
enable ngx_http_addition_module
具体选项配置说明配置命令./configure
这里选择默认的配置,Nginx将默认被安装到/usr/local/nginx目录之下.4. 编译安装make && make install
5. 验证是否安装成功[lidengyin@ldy nginx-1.9.9]$ nginx -v
nginx version: nginx/1.9.9
6. 修改配置文件在安装nginx的配置文件nginx.conf时,如果没有指定路径,则默认放在/usr/local/nginx/conf目录之下7. 验证配置文件的正确性,在启动Nginx之前,最好先检查一下配置文件是否正确,以免在重启Nginx之后出现错误,影响服务器稳定运行[root@ldy ~]$ 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
8. 配置防火墙9. 启动Nginx服务/usr/local/nginx/sbin/nginx
10. 查看Nginx进程信息ps -ef
grep nginx
11. 浏览器测试显示欢迎界面12. 关闭Nginx服务13. 加入自启动和系统服务创建脚本文件切换到/lib/systemd/system/目录,创建nginx.service文件vim nginx.service[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
# 路径对应安装路径
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
设置执行权限chmod -r 755 ./nginx.service执行systemctl start nginx.service
启动nginx
systemctl stop nginx.service
结束nginx
systemctl restart nginx.service
重启nginx
加入开启启动 systemctl enable nginx.service
14. 加入系统变量修改/etc/profile文件export NGINX_HOME=/usr/local/nginx
export PATH=${NGINX_HOME}/sbin:${PATH}
生效source /etc/profile
验证nginx -v
15. nginx -s 命令行参数验证配置是否正确: nginx
-t
查看Nginx的详细的版本号:nginx
-V
查看Nginx的简洁版本号:nginx
-v
启动Nginx:start
nginx
快速停止或关闭Nginx:nginx
-s
stop
正常停止或关闭Nginx:nginx
-s
quit
配置文件修改重装载命令:nginx
-s
reload

我要回帖

更多关于 centos7安装后出现localhost 的文章

 

随机推荐