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

46次课(Nginx安装 、 默认虚拟主机、Nginx用户认证、Nginx域名重定向)

时间:2018-08-14 00:56:18      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:src   ima   for   lob   linu   name   buffer   .net   errors   

Nginx安装

技术分享图片

进入/usr/local/src目录下

[root@100xuni1 ~]# cd /usr/local/src/         

技术分享图片

下载Nginx安装包可以去nginx.org或者https://coding.net/u/aminglinux/p/resource/git/blob/master/README.md下载

[root@100xuni1 src]# wget http://124.205.69.170/files/51490000069A64B9/nginx.org/download/nginx-1.14.0.tar.gz                    ##wget下载

技术分享图片

解压

[root@100xuni1 src]# tar zxf nginx-1.14.0.tar.gz      ##解压
[root@100xuni1 src]# cd nginx-1.14.0/                    ##解压完成后进入

技术分享图片

编译

[root@100xuni1 nginx-1.14.0]#  ./configure --prefix=/usr/local/nginx       ##编译

技术分享图片

make

[root@100xuni1 nginx-1.14.0]# make

技术分享图片

make install

[root@100xuni1 nginx-1.14.0]# make install

技术分享图片

nginx目录

[root@100xuni1 nginx-1.14.0]# ls /usr/local/nginx/       ##目录
conf  html  logs  sbin
[root@100xuni1 nginx-1.14.0]# ls /usr/local/nginx/conf/     ##配置文件目录
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default
[root@100xuni1 nginx-1.14.0]# ls /usr/local/nginx/html/       ##样例文件
50x.html  index.html
[root@100xuni1 nginx-1.14.0]# ls /usr/local/nginx/logs/            ##存放日志
[root@100xuni1 nginx-1.14.0]# ls /usr/local/nginx/sbin/      ##他的进程核心的文件
nginx

-t也是支持的查询配置文件是否有错

[root@100xuni1 nginx-1.14.0]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

给nginx创建配置文件还要给他做个启动脚本

[root@100xuni1 nginx-1.14.0]# vim /etc/init.d/nginx       ##启动脚本存放位置,配置这个文件内容去https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx 把这里的内容拷贝到nginx里

技术分享图片

改权限

[root@100xuni1 nginx-1.14.0]#  chmod 755 /etc/init.d/nginx

开机启动

[root@100xuni1 nginx-1.14.0]#  chkconfig --add nginx 
[root@100xuni1 nginx-1.14.0]# chkconfig nginx on 

编辑配置文件这个配置文件需要下载模板

[root@100xuni1 nginx-1.14.0]# cd /usr/local/nginx/conf/    ##进入配置文件
[root@100xuni1 conf]# ls          ##这个里边nginx.conf了不用他的用自己的,
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default
[root@100xuni1 conf]# mv nginx.conf nginx.conf.1   ##拷贝改名字

开始配置

[root@100xuni1 conf]# vim nginx.conf     ##去https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf下拷贝内容

user nobody nobody;                ##用来启动nginx是哪些用户
worker_processes 2;               ##定义子进程有几个
error_log /usr/local/nginx/logs/nginx_error.log crit;      ##错误日志
pid /usr/local/nginx/logs/nginx.pid;             ##pid
worker_rlimit_nofile 51200;       ##nginx最多打开多少个文件

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘
    ‘ $host "$request_uri" $status‘
    ‘ "$http_referer" "$http_user_agent"‘;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm 
    application/xml;

    server
    {
        listen 80;
        server_name localhost;
        index index.html index.htm index.php;
        root /usr/local/nginx/html;

        location ~ \.php$ 
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
        }    
    }
}
[root@100xuni1 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动

[root@100xuni1 conf]# /etc/init.d/nginx  start

技术分享图片

技术分享图片

默认虚拟主机

技术分享图片

Nginx用户认证

技术分享图片

技术分享图片

Nginx域名重定向

技术分享图片

46次课(Nginx安装 、 默认虚拟主机、Nginx用户认证、Nginx域名重定向)

标签:src   ima   for   lob   linu   name   buffer   .net   errors   

原文地址:http://blog.51cto.com/8043410/2159486

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