美文网首页
Nginx 配置,启动,重启

Nginx 配置,启动,重启

作者: ScottX | 来源:发表于2016-12-19 01:37 被阅读154次

一、下载
从官网http://nginx.org/en/download.html 下载稳定版(目前最新稳定版是1.6.2)
二、解压
tar zxf nginx-1.6.2.tar.gzcd nginx-1.6.2
三、配置
./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo
注:prefix指定安装目录,user指定运行nginx的用户身份
通常第一次并不会顺利成功,如果出现:
./configure: error: the HTTP rewrite module requires the PCRE library.
表示当前机器上没有PCRE包,可以手动安装:
sudo yum -y install pcre-devel
再次运行./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo,又有新的错误:
./configure: error: the HTTP gzip module requires the zlib library.
类似的,手动安装zlib包
sudo yum -y install zlib-devel
继续重复刚才的./configure命名,如果出现:
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
继续手动安装open-ssl
yum -y install openssl openssl-devel
一切ok后,接下来可以编译了
四、编译
make install
注:需要gcc环境,如果没有安装gcc,请先安装gcc,方法 yum -y install gcc
顺利的话,会在/opt/app/nginx/1.6.2路径下生成很多文件
五、启动
cd /opt/app/nginx/1.6.2/sbin
./nginx
如果出现:
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
多半是80端口被占用
cd /opt/app/nginx/1.6.2/conf
vi nginx.conf
找到下面的内容:
server { listen 80; server_name localhost; #charset koi8-r;
将80端口改成其它端口,比如7040(当然也可以把跟80冲突的进程给kill掉),然后再回到sbin目录,重复./nginx
正常的话,用ps -ef|grep nginx应该可以看到2个进程:
[cargo@vm-vmw1813-app sbin]$ ps -ef|grep nginxcargo 4180 1 0 14:38 ? 00:00:00 nginx: master process ./nginxcargo 4181 4180 0 14:38 ? 00:00:00 nginx: worker process
表示启动正常,可以用浏览器 访问 http://ip:7040/ 如果出现以下图片:


恭喜,安装成功!
其它一些有用的启动参数:
1
2
3
4
5
6
7
8
9
10
11
12

Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:

-?,-h : this help

v
: show version and
exit

-V : show version and configure options
then
exit

-t :
test
configuration and
exit

-q : suppress non-error messages during configuration testing

-s signal : send signal to a master process: stop, quit, reopen, reload

-p prefix :
set
prefix path (default:
/usr/local/Cellar/nginx/1
.8.0/)

-c filename :
set
configuration
file
(default:
/usr/local/etc/nginx/nginx
.conf)

-g directives :
set
global directives out of configuration
file

特别要提一下-V(大写),有时候不知道配置文件在哪,用这个参数就能查出来。

六、卸载、停止服务
卸载只要把目录删除掉就行了,如果自己为了运维方便,做了其它启动的脚本,同步删除
停止服务,直接kill掉nginx进程最直接。
当然也可以 ./nginx -s stop

相关文章

  • nginx启动、重启、关闭

    启动 重启 service nginx reload平滑重启 更改配置重启nginx 判断配置文件是否正确 关闭查...

  • CentOS 中Nginx启动、重启、关闭

    一、启动 cd usr/local/nginx/sbin ./nginx 二、重启 更改配置重启nginx kil...

  • 二、指令

    nginx启动: nginx停止: 修改配置文件后检查配置文件 重启

  • Lesson-26 Nginx

    nginx启动、关闭、重启 开启 nginx 重新加载配置|重启|停止|退出 nginxnginx -s relo...

  • Niginx命令

    nginx启动: nginx重启: nginx配置文件: /etc/nginx/sites-enabled/def...

  • 应用程序常用命令

    nginx: nginx启动:nginx -c nginx配置文件地址检查配置文件是否正确:nginx -t重启n...

  • nginx 开始 停止 重启

    Nginx的启动、停止与重启 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [...

  • Nginx基本使用

    启动、关闭、重启 nginx.conf文件简单配置

  • Nginx+Gunicorn

    1.Nginx 安装 启动,停止和重启 or 配置nginx 编辑/etc/nginx/sites-enabled...

  • nginx简易安装和配置

    环境 centos7.4 安装nginx 下载 解压 安装 启动、重启、停止、退出 配置 反向代理 nginx配置...

网友评论

      本文标题:Nginx 配置,启动,重启

      本文链接:https://www.haomeiwen.com/subject/nkgzmttx.html