1 - 安装Nginx

官网步骤:http://nginx.org/en/linux_packages.html#RHEL-CentOS

[Anliven@h202 ~]$ sudo vim /etc/yum.repos.d/nginx.repo
[Anliven@h202 ~]$
[Anliven@h202 ~]$ cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[Anliven@h202 ~]$
[Anliven@h202 ~]$ sudo yum -y install nginx
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirror.bit.edu.cn
......
......
......
Verifying : 1:nginx-1.16.1-1.el7.ngx.x86_64 1/1
Installed:
nginx.x86_64 1:1.16.1-1.el7.ngx
Complete!
[Anliven@h202 ~]$

2 - 配置Nginx

2.1 修改默认配置

配置文件: /etc/nginx/conf.d/default.conf 

[Anliven@h202 ~]$ cd /etc/nginx/conf.d/
[Anliven@h202 conf.d]$ pwd
/etc/nginx/conf.d
[Anliven@h202 conf.d]$ ll
total 4
-rw-r--r-- 1 root root 1093 Aug 13 23:02 default.conf
[Anliven@h202 conf.d]$
[Anliven@h202 conf.d]$ sudo vim default.conf
[Anliven@h202 conf.d]$ cat default.conf |grep -v "#" |grep -Ev "^$"
server {
listen 80;
server_name 192.168.16.202;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
[Anliven@h202 conf.d]$

2.2 修改Nginx配置文件

/etc/nginx/nginx.conf中user参数,修改为root

[Anliven@h202 ~]$ sudo vim /etc/nginx/nginx.conf
[Anliven@h202 ~]$
[Anliven@h202 ~]$ cat /etc/nginx/nginx.conf |grep -v "#" |grep -Ev "^$"
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
[Anliven@h202 ~]$

2.3 确认防火墙状态并重启服务

[Anliven@h202 ~]$ sudo firewall-cmd --zone=public --permanent --add-port=80/tcp
success
[Anliven@h202 ~]$ sudo firewall-cmd --reload
success
[Anliven@h202 ~]$ sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: ssh dhcpv6-client
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules: [Anliven@h202 ~]$
[Anliven@h202 ~]$ cat /etc/selinux/config |grep "SELINUX=" |grep -v "#"
SELINUX=disabled
[Anliven@h202 ~]$
[Anliven@h202 ~]$ sudo service nginx restart
Redirecting to /bin/systemctl restart nginx.service
[Anliven@h202 ~]$

3 - 访问页面

/usr/share/nginx/目录下的index.html文件,就是关于nginx介绍的页面

3.1 访问Nginx介绍页面

http://192.168.16.202/

3.2 修改Nginx介绍页面

[Anliven@h202 html]$ pwd
/usr/share/nginx/html
[Anliven@h202 html]$
[Anliven@h202 html]$ sudo vim index.html
[Anliven@h202 html]$ cat index.html
<!DOCTYPE html>
<html>
<head>
<title>This is a test!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to MyNginx!</h1>
<p>Action is the antidote to despair!</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[Anliven@h202 html]$

刷新浏览器页面

Nginx - 安装并启动Nginx的更多相关文章

  1. linux系统下nginx安装目录和nginx.conf配置文件目录

    linux系统下nginx安装目录和nginx.conf配置文件目录 1.查看nginx安装目录 输入命令 # ps  -ef | grep nginx 返回结果包含安装目录 root      26 ...

  2. linux 安装与启动nginx

    linux系统为Centos 64位 一.去http://nginx.org/download/上下载相应的版本下载nginx-1.8.0.tar.gz(注:还有更高版本的). 二.解压 tar -z ...

  3. linux centos-7.2-64bit 安装配置启动nginx

    1.安装依赖包yum -y install openssl openssl-develyum install pcre*yum install openssl*yum install zlib yum ...

  4. nginx 安装、启动、重启、关闭 (linux系统命令行)

    前言: 最近在部署我的hexo静态博客到腾讯云服务器上,用到了很多nginx的知识,在此做下总结: 刚接触的linux服务器上,nginx配置乱的有点令人发指,就把老的卸载了重新装一下. 1.卸载 y ...

  5. Nginx 安装与启动

    安装 第一种安装方式:CentOS 7下配置 yum 安装 Nginx. 按照官方的安装实例:https://www.nginx.com/resources/admin-guide/ 第一步,在/et ...

  6. mac系统下安装和启动nginx

    1.在线安装 localhost:nginx-1.17.1 mhx$ sudo brew install nginx 2.查看是否安装成功 localhost:nginx-1.17.1 mhx$ ng ...

  7. 002.Nginx安装及启动

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

  8. Nginx安装及配置文件nginx.conf详解

    1.安装Nginx 在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库. 下面是Nginx安装过程: wget http ...

  9. Nginx安装与配置文件nginx.conf详解

    引用“http://ixdba.blog.51cto.com/2895551/790611” 1.安装Nginx在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcr ...

随机推荐

  1. Beta冲刺(3/7)——2019.5.24

    所属课程 软件工程1916|W(福州大学) 作业要求 Beta冲刺(3/7)--2019.5.24 团队名称 待就业六人组 1.团队信息 团队名称:待就业六人组 团队描述:同舟共济扬帆起,乘风破浪万里 ...

  2. reduce要素与适用总结

    要素: 1.高阶函数:reduce: 2.处理函数:reducer: 3.数据:可以是具体数据.签名相同的普通函数.签名相同的高阶函数: reduce(reducer, datas(data or f ...

  3. 使用apache 的FileUtils处理文件的复制等操作

    今日思语:春风很柔,夏风很烈,秋风清爽,东风凛冽,愿你就是春夏秋冬的风~ 平时对一些文件进行操作,比如说写文件,读文件,复制一个文件等,使用原生File操作需要读取源文件,生成流对象,再写入一个新的文 ...

  4. SC CSP-J2019初赛成绩已出!

    链接: https://pan.baidu.com/s/1UK2pL7UW0n0vYpnzMbJm9A 提取码: uwav 复制这段内容后打开百度网盘手机App,操作更方便哦 Me?87! I am  ...

  5. 关于windows使用git警告LF will be replaced by CRLF

    由于windows平台的换行符是CRLF,但是我们引用别人的类库可能是在unix平台开发的,那么代码中的换行符是LF,而git默认会做这个转换,所以在用git提交这些代码时会有警告:LF will b ...

  6. Java finally未被执行的情况

    一种是先执行了用于终止程序的System.exit()方法,或进程被关闭 还有一种情况是,当前线程一直在执行,在一些业务逻辑里面跳不出来,看上去就像finally一直未被执行 线程被终止的时候也会执行 ...

  7. getaddrinfo工作原理分析

    getaddrinfo工作原理分析 将域名解析成ip地址是所有涉及网络通讯功能程序的基本步骤之一,常用的两个接口是gethostbyname和getaddrinfo,而后者是Posix标准推荐在新应用 ...

  8. java判断指定路径文件夹是否存在,若不存在则创建新的文件夹

    File file = new File(dirPath); if (!file.exists()) { file.mkdirs(); }

  9. vue-router踩坑日记Unknown custom element router-view

    今天笔者在研究vue-router的时候踩到了一个小坑,这个坑是这样的 笔者的具体代码如下:router.js import Home from '@/components/Home.vue'; im ...

  10. 防止同一IP多次请求攻击

    防止同一IP多次请求攻击 防止入侵者,通过死循环同一时间批量向服务器请求数据,导致服务器内存开销不断膨胀,最后直接瘫痪. 一. 新增一个spring的拦截器 , 拦截所有请求 <mvc:inte ...