安装
第一种安装方式:CentOS 7下配置 yum 安装 Nginx。
按照官方的安装实例:https://www.nginx.com/resources/admin-guide/
第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo
cd /etc/yum.repos.d/vim nginx.repo

填写如下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

保存,则会产生一个/etc/yum.repos.d/nginx.repo文件。

下面直接执行如下指令即可自动安装好Nginx:

yum install nginx -y

第二种:在各平台上直接执行对应安装命令

# CentOS
yum install nginx;
# Ubuntu
sudo apt-get install nginx;
# Mac
brew install nginx;


启动

接下来看一下nginx的安装路径:

[root@localhost ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
[root@localhost ~]# 

cd切换到 /usr/sbin/nginx,使用./nginx启动nginx

如果出现:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

多半是80端口被占用,可以通过修改nginx启动的配置文件来修改,配置文件地址:/etc/nginx/nginx.conf

正常的话,用 ps -ef|grep nginx 应该可以看到2个进程:

[root@localhost ~]#  ps -ef|grep nginx
root      4804     1  0 3月26 ?       00:00:00 nginx: master process ./nginx
nginx     4805  4804  0 3月26 ?       00:00:00 nginx: worker process

表示启动正常,可以使用curl http://localhost 查看nginx输出内容,或者是通过浏览器来查看nginx欢迎界面

其它一些有用的启动参数:

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(大写),有时候不知道配置文件在哪,用这个参数就能查出来。

[root@localhost ~]# nginx -V
nginx version: nginx/1.10.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
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-file-aio --with-threads --with-ipv6 --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_ssl_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'

从输出内容可以看出里面包含了nginx启动的文件,启动的配置文件,以及一些其他的参数

也可以通过nginx -t来检查配置文件是否正确

卸载、停止服务

卸载只要把目录删除掉就行了,如果自己为了运维方便,做了其它启动的脚本,同步删除停止服务,直接kill掉nginx进程最直接。

当然也可以 ./nginx -s stop

转载于:https://www.cnblogs.com/duhuo/p/4530330.html

Nginx 安装与启动相关推荐

  1. mac nginx安装、启动、简单命令

    一. brew 安装 打开mac终端,输入以下命令: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ins ...

  2. ubuntu nginx 安装和启动和自启动

    ngx_http_core_module 模块http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html 目 ...

  3. flacs 安装教程_002.Nginx安装及启动

    一 Nginx yum安装 1.1 前置准备 1 [[email protected] ~]# systemctl status firewalld.service#检查防火墙 2 [[email p ...

  4. Nginx安装与启动

    下载: Nginx开源版 http://nginx.org/ Nginx plus 商业版 https://www.nginx.com openresty http://openresty.org/c ...

  5. Nginx安装及详细配置

    前言 公司项目是一个前后端分离的项目. 生产环境:前端采用nginx进行的部署,后端则是通过kubesphere的一键式部署. 再此,就记录一下nginx搭建过程,分享给小伙伴们,避免时间的浪费 安装 ...

  6. centos 查找nginx_centos7 nginx安装/启动/进程状态/杀掉进程

    1.安装 如果找不wget请安装,命令:yum -y install wget 2.安装成功后nginx的几个默认目录 输入命令: whereis nginx 执行目录:/usr/sbin/nginx ...

  7. linux下nginx安装与设置开机启动

    http://www.myhack58.com/Article/sort099/sort0102/2015/66341.htm 环境准备 yum -y install gcc gcc-c++ auto ...

  8. 解决办法在安装完Nginx后服务启动失败

    在安装完Nginx后服务启动失败的解决办法 systemctl start nginx //启动服务 Job for nginx.service failed because the control ...

  9. 启动代码格式:nginx安装目录地址 -c nginx配置文件地址

    启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /us ...

最新文章

  1. 详解 CQRS 架构模式
  2. 全北现代宣布江苏苏宁中后卫洪正好租借延长1年
  3. 苹果mp3软件_神技能!!!音视频制作软件
  4. 在.net中读写config文件的各种方法(转载)
  5. 为什么grpc不支持php,带入gRPC:让你的服务同时提供 HTTP 接口
  6. socket read time out解决方法_time_after方法对jiffies回绕问题的解决
  7. 打破“信息孤岛”不能透支信息安全
  8. AI Challenger 2018:细粒度用户评论情感分类冠军思路总结
  9. python爬虫需要学哪些知识_Python爬虫需要学习那些东西?
  10. 计算机网络实验——ns3仿真最短路由选择算法
  11. VMware ESXi 安装
  12. 计算机在录制声音过程中流向,Bandicam中录制电脑声音的具体流程介绍
  13. Win7常见问题和技巧整
  14. overscroll-behavior
  15. 念悠文化:微博运营怎么做?微博运营的几个方法
  16. 力扣:17. 电话号码的字母组合
  17. 我看:“不患寡而患不均” 以及 “饥寒起盗心”
  18. 第三章 Elasticsearch Query DSL -- 查询
  19. Unity 灯光设置——灯光类型
  20. 【看表情包学Linux】Redirect 重定向 | 时间相关指令 | 文件查找 | 打包与压缩

热门文章

  1. 三、Vue组件化开发学习笔记——组件化的基本步骤、全局组件和局部组件、父组件和子组件、注册组件的语法糖、模板分离写法、组件的数据存放
  2. Chapter7-11_Deep Learning for Question Answering (2/2)
  3. LeetCode 1602. 找到二叉树中最近的右侧节点(BFS)
  4. LeetCode 284. 顶端迭代器
  5. LeetCode 1380. 矩阵中的幸运数(set)
  6. dev c++ 代码补全_zsh配置与代码自动补全+tmux配置
  7. python中的异步与同步
  8. java jsoup获取cookie_java – 如何使用jsoup维护变量cookie和会话?
  9. 吐槽贴:用ELECTRA、ALBERT之前,你真的了解它们吗?
  10. Reactor三种线程模型与Netty线程模型