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. ES6 的class类 笔记

    class Person{ // 构造 constructor(x,y){ this.x = x; this.y = y; } toString(){ return (this.x + "的 ...

  2. 浏览器渲染详细过程:重绘、重排和 composite 只是冰山一角

    https://juejin.im/entry/590801780ce46300617c89b8 渲染 这张很经典的图许多人都看过,其中的概念大家应该都很熟悉,也就是这么几个步骤:js修改dom结构或 ...

  3. vue cli4.0 配置环境变量

    温馨提示:本文只适用于vue-cli 3.0 及以上的版本哦~ ------------------正文开始------------------ 开发项目时,经常会需要在不同环境中切换.那么我们如何配 ...

  4. POJ1321-棋盘问题-(dfs)

    http://poj.org/problem?id=1321 解题: dfs中,两种情况,某一行摆不摆?某一列摆不摆? #include<stdio.h> #include<iost ...

  5. 重温Elasticsearch

    什么是 Elasticsearch ? Elasticsearch (ES) 是一个基于 Lucene 构建的开源.分布式.RESTful 接口全文搜索引擎.还是一个分布式文档数据库,其中每个字段均是 ...

  6. 【C/C++】static关键字

    首先static的最主要功能是隐藏,其次因为static变量存放在静态存储区,所以它具备持久性和默认值0. static性质 隐藏 当同时编译多个文件时,未加static前缀的全局变量和函数都具有全局 ...

  7. .ckpt文件与.pb文件

    .ckpt文件是旧版本的输出saver.save(sess),相当于现在的.ckpt-data checkpoint文件仅用于告知某些TF函数,这是最新的检查点文件. .ckpt-meta 包含元图, ...

  8. plotly-dash 简单使用(一)

    plotly-dash 是一个很不错的dashboard 开发平台,基于python 编写,提供了很便捷的dashboard 开发模型 同时扩展上也比较灵活我们可以编写自己的组件. 以下是一个简单的项 ...

  9. 网卡可以绑定cpu提高吞吐量

    请看大神帖子:https://blog.csdn.net/nawenqiang/article/details/82854929 需要做什么呢? 首先,确认你是否运行irqbalance,这个是nic ...

  10. Exploiting ConvNet Diversity for Flooding Identification

    语义分割洪水区域. 空洞卷积和反卷积组合,结果再用svm学习如何组合,能获得更好的效果. 直接对不同网络的结果进行投票会得到更差的结果. 消融研究(Ablation Study):类似控制变量法,就对 ...