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. beforeRouteEnter 与 beforeRouteUpdate(watch $route 对象) 的区别

    项目 区别 适用场景 网址 beforeRouteEnter beforeRouteEnter 守卫 不能 访问 this,因为守卫在导航确认前被调用,因此即将登场的新组件还没被创建.不过,你可以通过 ...

  2. HDU5421 Victor and String 和 APIO2014 回文串

    两道差不多的题,都是回文自动机right集合处理相关. Victor and String Victor loves to play with string. He thinks a string i ...

  3. AHOI2014 奇怪的计算器 和 HDU5306 Gorgeous Sequence

    线段树秀操作题. 奇怪的计算器 有 N 个数,一共会对这 N 个数执行 M 个指令(对没个数执行的指令都一样),每一条指令可以是以下四种指令之一:(这里 a 表示一个正整数) 加上 a 减去 a 乘以 ...

  4. reactnative 笔记

    1.<FlatList/> _renderItem = ({item})=>{ return <View style={[styles.part4Row]}> <T ...

  5. 实现:创建/复制/移动文件API

    使用的API: 1.DeleteFile DeleteFileW( _In_ LPCWSTR lpFileName ); 2.CopyFile CopyFileW( _In_ LPCWSTR lpEx ...

  6. 68-Flutter中极光推送的使用

    1.申请极光账号和建立应用 极光推送的官方网址为:https://www.jiguang.cn/ 注册好后,进入'服务中心',然后再进入'开发者平台',点击创建应用. 这时候会出现新页面,让你填写“应 ...

  7. 16-Flutter移动电商实战-切换后页面状态的保持AutomaticKeepAliveClientMixin

    底栏切换每次都重新请求是一件非常恶心的事,flutter 中提供了AutomaticKeepAliveClientMixin 帮我们完成页面状态保存效果. 1.AutomaticKeepAliveCl ...

  8. 在调试时,有什么更好的方法可以监视最后一个win32错误?

    我发现在代码中使用win32api时,需要多次监视最后一个win32错误!(在每次使用API后调用GetLastError()是不可行的解决方案!).. 在Visual Studio中,它们提供了一个 ...

  9. codeblock代码片段

    for循环 ; $(index name)<| ; $(index name)++ ){ } 2. 反向for循环 ; $(index name)>= ; $(index name)-- ...

  10. 灰度图像--图像分割 Prewitt算子

    学习DIP第45天 转载请标明本文出处:http://blog.csdn.net/tonyshengtan,欢迎大家转载,发现博客被某些论坛转载后,图像无法正常显示,无法正常表达本人观点,对此表示很不 ...