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. Linux—— 报错汇总

    前言 记录Linux相关的错误问题和解决方法 问题 tar: Error is not recoverable: exiting now [报错] tar -zxvf mysql-server_5.6 ...

  2. 封装好的cookie的三个常用函数 cookie的添加、删除、提取操作函数

    function addCookie(name,value,expiresHours){   //添加一个cookie.  三个参数:cookie的名称.值.有效时间(为0时,关闭浏览器cookie消 ...

  3. ThreadLocal如何回收value,什么时候回收?(学习笔记)

    1)ThreadLocal如何回收value,什么时候回收?从ThreadLocal中的内部类分析:① static class ThreadLocalMap { /** * The entries ...

  4. mybatis include refid="Base_Column_List"含义

    <sql id="Base_Column_List" > collegeID, collegeName </sql> <select id=" ...

  5. Xamarin.Forms之样式

    使用XAML样式设置Xamarin.Forms应用的样式Xamarin.Forms应用程序的样式传统上是通过使用Style类将一组属性值分组到一个对象中来完成的,然后可以将其应用于多个视觉元素实例. ...

  6. ent 基本使用十八 查询谓词

    ent 生成的代码包含了比较完整的查询谓词 字段谓词 Bool: =, != Numeric: =, !=, >, <, >=, <=, IN, NOT IN Time: =, ...

  7. Spring Could Feign 设计原理

    什么是Feign? Feign 的英文表意为"假装,伪装,变形", 是一个http请求调用的轻量级框架,可以以Java接口注解的方式调用Http请求,而不用像Java中通过封装HT ...

  8. Ubuntu下python3安装tkinter包

    case1: 首先sudo apt-get update(如果不更新很有可能找不到tkinter),然后sudo apt-get install python3-tk,安装完成后就可以使用了. cas ...

  9. Java实现PV操作 | 生产者与消费者

    导语 在学习操作系统的过程中,PV操作是很重要的一个环节.然而面对书本上枯燥的代码,每一个爱好技术的人总是想能亲自去实现.现在我要推出一个专题,专门讲述如何用Java实现PV操作,让操作系统背后的逻辑 ...

  10. spring注解式参数校验列表

    校验注释列表: @AssertFalse Boolean,boolean 验证注解的元素值是false @AssertTrue Boolean,boolean 验证注解的元素值是true @NotNu ...