码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx安装和域名配置

时间:2018-04-20 20:45:00      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:family   访问   pes   login   没有   time   erer   client   direct   

一、安装必要的库

yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

二、创建nginx用户和组

groupadd www
useradd -s /sbin/nologin -g www -M www    #创建一个用户,不允许登陆和不创主目录 

三、下载并解压nginx

wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -xzvf nginx-1.12.0
cd nginx-1.12.0

四、配置并编译安装

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre

--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-http_realip_module:在nginx访问日志中去除代理IP,显示客户的真实IP
--with-http_gzip_static_module:启用静态压缩
--with-pcre:为了支持rewrite重写功能,必须制定pcre

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

出现如上信息表上configure成功,执行:

make && make install

五、启动、关闭、重启nginx

启动:直接执行以下命令,nginx就启动了,不需要改任何配置文件

# /usr/local/nginx/sbin/nginx
# curl -s http://localhost  #即可查看目录下的默认index.html页面

关闭:

查询nginx主进程号  ps -ef | grep nginx
从容停止   kill -QUIT 主进程号
快速停止   kill -TERM 主进程号
强制停止   kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 /usr/local/nginx/logs/nginx.pid

更改配置重启nginx:

kill -HUP 主进程号或进程号文件路径
#或者
/usr/local/nginx/sbin/nginx -s reload

注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:

nginx -t -c /usr/local/nginx/conf/nginx.conf
#或者
/usr/local/nginx/sbin/nginx -t

六、域名配置

在"/usr/local/nginx/conf"目录下新建"vhost"目录,所有的站点配置文件放在vhost中

"/usr/local/nginx/conf/nginx.conf"配置如下:

user  www www;
worker_processes  8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

error_log  logs/error.log  notice;

pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections  1024;
}


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;

    server_tokens   off;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    client_header_buffer_size 4k;

    open_file_cache max=65535 inactive=60s;
    open_file_cache_valid 60s;
    open_file_cache_min_uses 1;

    include vhost/*.conf;
}

"/usr/local/nginx/conf/vhost/default.conf"配置如下(未解析php):

server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        access_log  logs/default.access.log  main;

        root /data/www/default/;
        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;
        }
}

 

Nginx安装和域名配置

标签:family   访问   pes   login   没有   time   erer   client   direct   

原文地址:https://www.cnblogs.com/gimin/p/8893209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!