6月7日任务

时间:2022-05-12 14:21:26

12.6 Nginx安装

安装过程

# cd /usr/local/src

# wget http://nginx.org/download/nginx-1.14.0.tar.gz  (一般来说,偶数版本为稳定版,适合生产环境)

# tar xzf nginx-1.14.0.tar.gz  

# cd nginx-1.14.0/

# ./configure --prefix=/usr/local/nginx

# make && make install

设置过程

# cd /usr/local/nginx/conf/

# mv nginx.conf nginx.conf1   //把系统自带的配置文件改名备份

# vim nginx.conf          //创建新的配置文件,写入以下内容,参考链接

user nobody nobody;
worker_processes 2;
error_log /usr/local /nginx/logs/nginx_error.log crit;
pid /usr/local /nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
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;
}
}
}
# chmod 755  /etc/init.d/nginx

#/etc/init.d/nginx start

# ps aux |grep nginx

6月7日任务

# ps aux |grep php-fpm

6月7日任务


测试

# curl localhost

6月7日任务


#vim /usr/local/nginx/html/1.php  //创建一个php文件,简单写入以下内容

6月7日任务

# curl localhost/1.php   //可以正常解析php

6月7日任务



12.7 Nginx默认虚拟主机

# vim /usr/local/nginx/conf/nginx.conf           //编辑配置文件,删除最后几行并添加一行内容

6月7日任务

# mkdir /usr/local/nginx/conf/vhost

#cd /usr/local/nginx/conf/vhost

# vim aaa.com.conf            //新建并添加如下内容

server
{
    listen 80 default_server;   //有这个标记就是默认虚拟主机
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/wwwroot/default;
}

6月7日任务


# mkdir  -p /data/wwwroot/default

# echo “This is a default site.”>/data/wwwroot/default/index.html

# /usr/local/nginx/sbin/nginx -t    //检查语法

6月7日任务

# /usr/local/nginx/sbin/nginx -s reload  //重新加载


测试

# curl localhost

6月7日任务


下面说一下总结默认虚拟主机的两种方法

1.在/usr/local/nginx/conf/vhost目录下排在第一位,比如下面aaa.com.conf就是默认的虚拟主机

6月7日任务

2.改配置文件

6月7日任务


12.8 Nginx用户认证

#vim /usr/local/nginx/conf/vhost/test.com.conf       //写入如下内容

server
{
    listen 80;
    server_name test.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    
location  /
    {
        auth_basic              "Auth";
        auth_basic_user_file   /usr/local/nginx/conf/htpasswd;
}
}
6月7日任务

# yum install -y httpd