nginx基本配置命令及方法

nginx最新稳定版本为1.12.0,其安装文件可以从官方网站http://www.nainx.org/下载,下面以稳定版1.12.0为例介绍安装nginx
下面拿vmware workstation 虚拟机为实验环境给大家做一下
1) yum -y install pcre-devel zlib-devel.x86_64 //安装支持软件
**2)**useradd -M -s /sbin/nologin nginx //创建运行nginx的用户和组
3)编译安装nginx

tar zxvf nginx_1.12.0.tar.gz -C /usr/src  //从网上下载的压缩包解压到指定路径
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module   //具体选项根据实际需求来订,可参考"./configure --help"
make && make install //编译安装

4)为使管理员直接运行“ngnx”创建一软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
5)接下来就直接启动nginx
nginx
netstat -anpt | grep nginx //查看服务是否运行
为使nginx服务的启动停止重载更加方便,可编写nginx 服务脚本
(你以为我下面要写脚本,NO,NO,NO,懒得写!!!如果有需要的自行百度,格式都一样)
6) 下面改一下nginx的配置文件
路径为/usr/local/conf/nginx.conf
里面的配置文件分为三部分
(1)全局配置

#user  nobody;  //运行用户
worker_processes  1; //工作进程数量

#error_log  logs/error.log; 错误日志文件的位置
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid; //PID文件的位置

(2)I/O事件配置

events {
    worker_connections  1024; //每进程处理1024个连接
}

(3)HTTP配置

http {
    include       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  logs/access.log  main; //访问日志位置


    sendfile        on;
    #tcp_nopush     on;  

    #keepalive_timeout  0;
    keepalive_timeout  65; //连接保持超时

    #gzip  on;

    server {  //web服务的监听配置
        listen       80; //监听地址及端口
        server_name  localhost; //网站名称

#charset koi8-r;

        #access_log  logs/host.access.log  main; 

        location / { //根目录配置
            root   html; //网站根目录的位置,相对于安装目录
            index  index.html index.index.php; //默认首页
        }

        #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;
        }


根据实际情况进行更改

猜你喜欢

转载自blog.csdn.net/qq_43058722/article/details/82178495