Nginx学习入门一

1. 基本介绍

Nginx是高性能的http/https和反向代理服务器,特点是占用内存少,处理高并发能力强大。有报告表明Nginx能够支持50000个并发连接数。

2. 安装

安装环境:CentOS7

1) 安装gcc-c++

yum install gcc-c++

2) 安装pcre

wget http://downloads.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz

tar -xvf pcre-8.44.tar.gz

./configigure

make

make install

3) 安装opensslzlibgcc

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

4) 安装nginx

官网下载:http://nginx.org/

tar -xvf nginx-1.16.1.tar.gz

./configigure

make

make install

3. 命令

nginx安装目录:/usr/local/nginx

命令行操作nginx前,先cd/usr/local/nginx/sbin

查看版本号   ./nginx -v

启动nginx    ./nginx

停止nginx    ./nginx -s stop

重加载nginx  ./nginx -s reload

4. 访问nginx主页

centos防火墙默认关闭80端口,外网需要访问到该服务,需要开放对应端口号

查看防火墙开放全部端口号

firewall-cmd --list-all

添加端口号

firewall-cmd --add-service=http --permanent

firewall-cmd --add-port=80/tcp --permanent

重启防火墙

Firewall-cmd --reload

5. nginx配置文件

#user  nobody;

# 全局块

worker_processes  1; # 工作进程数

# 事件块

events {

    worker_connections  1024;  # 单个工作进程连接数

}

# http

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    sendfile        on;

#tcp_nopush     on;

 

    keepalive_timeout  65; # 保活超时检测时间

 

    #gzip  on;

    server {

        listen       80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

 

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

 

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #   fastcgi_pass   127.0.0.1:9000;

        #   fastcgi_index  index.php;

        #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #   include        fastcgi_params;

        #}

 

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

 

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

 

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

 

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

posted @ 2020-04-23 21:36  随性者也  阅读(195)  评论(0编辑  收藏  举报