zoukankan      html  css  js  c++  java
  • Nginx

    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 {
             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]$ 
    

    刷新浏览器页面

  • 相关阅读:
    2019-9-2-C#枚举中使用Flags特性
    2019-9-2-C#枚举中使用Flags特性
    2019-8-31-C#-转换类型和字符串
    2019-8-31-C#-转换类型和字符串
    2019-8-31-C#-获取进程退出代码
    2019-8-31-C#-获取进程退出代码
    access truncate
    GIT分布式版本控制系统
    iSCSI的配置(target/initiator)
    chkconfig命令
  • 原文地址:https://www.cnblogs.com/anliven/p/12004102.html
Copyright © 2011-2022 走看看