linux部署nginx

1、安装依赖包

# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel kernel-devel  popt-devel libnl libnl-devel libnfnetlink-devel wget 

2、创建下载路径

# mkdir /home/setup #创建setup路径(下载文件放到这里)已创建的跳下一步
# cd /home/setup #切换到setup路径下
# wget http://nginx.org/download/nginx-1.13.0.tar.gz #下载

3、安装nginx

# tar -zxvf nginx-1.13.0.tar.gz #解压
#cd nginx-1.13.0 #切换路径
#useradd www -M -s /sbin/nologin #添加www用户,其中-M参数表示不添加用户目录,-s参数表示指定shell类型
 # vi auto/cc/gcc  #将这句注释掉 取消Debug编译模式 大概在179行
----------------编辑
#CFLAGS="$CFLAGS -g"
----保存退出

4、编译nginx(根据项目需要进行编译对应扩展)

# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-mail
#make && make install #安装
#echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local #配置开机自启
#mkdir /home/nginx 
#mkdir /home/nginx/conf  #nginx配置文件路径
#chmod -R a+x /home/nginx/conf #添加执行权限
注:新增加脚本均需要给与执行权限 
如:web.conf chmod -R a+x /home/nginx/conf/web.conf

5、nginx.conf配置

############################################# nginx.conf
user  www www;
worker_processes  4;     #cpu核数1/2
error_log  /var/log/ngerror.log;   #错误日志
worker_rlimit_nofile 65536;
events {
    worker_connections  4096;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    charset utf-8;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;
    client_max_body_size 1000M;    #上传文件大小
    fastcgi_connect_timeout 3000;
    fastcgi_send_timeout 3000;
    fastcgi_read_timeout 3000;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 8 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
    #proxy_buffer_size  128k;    #缓存
    #proxy_buffers   32 32k;    #缓存
   # proxy_busy_buffers_size 128k;    #缓存
    #proxy_temp_file_write_size 128k;  #缓存
    #proxy_cache_path /var/www/cache levels=1:2 keys_zone=mycache:20m max_size=2048m inactive=60m;  #缓存
    #proxy_temp_path /var/www/cache/tmp;  #缓存
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
    gzip_vary on;
    ## includes vhosts
    include /usr/local/nginx/*.conf;
    include /home/nginx/conf/*.conf;
}
##############################################

6、nginx启动

启动nginx
#/usr/local/nginx/sbin/nginx
重启nginx 
#/usr/local/nginx/sbin/nginx -s reload
停止nginx
#/usr/local/nginx/sbin/nginx -s stop

7、测试网站
1) 配置web.conf

#cd /home/nginx/conf #切换路径
#vi web.conf # 配置基于thinkphp的网站
#################################################编辑
server {
listen 80;  #端口80
server_name all; #域名或者IP
root /home/web; #网站路径
# access_log /home/nginx/logs/access.log; #错误日志路径
# error_log /home/nginx/logs/error.log; #错误日志路径
index index.html index.htm;   #首页配置

location ~ .*\.(gif|jpg|jpeg|png|bmp)$ {
expires 100d;
}
location ~ .*\.(js|css)?$ {
expires 30d;
}
error_page 500 502 503 504 /50x.html;
}
--------------------------------保存退出

2)创建网站

#mkdir /home/web
#cd /home/web
#vi index.html
--------------编辑
我是测试网站!!!
-----------保存

重启nginx如下
#/usr/local/nginx/sbin/nginx -s reload

3)访问测试

#curl http://ip
#我是测试网站!!!

OK 成功

猜你喜欢

转载自blog.csdn.net/weixin_36914964/article/details/81776808
今日推荐