46次课(Nginx安装 默认虚拟主机Nginx用户认证Nginx域名重定向)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了46次课(Nginx安装 默认虚拟主机Nginx用户认证Nginx域名重定向)相关的知识,希望对你有一定的参考价值。
nginx安装
进入/usr/local/src目录下
[[email protected] ~]# cd /usr/local/src/
下载Nginx安装包可以去nginx.org或者https://coding.net/u/aminglinux/p/resource/git/blob/master/README.md下载
[[email protected] src]# wget http://124.205.69.170/files/51490000069A64B9/nginx.org/download/nginx-1.14.0.tar.gz ##wget下载
解压
[[email protected] src]# tar zxf nginx-1.14.0.tar.gz ##解压
[[email protected] src]# cd nginx-1.14.0/ ##解压完成后进入
编译
[[email protected] nginx-1.14.0]# ./configure --prefix=/usr/local/nginx ##编译
make
[[email protected] nginx-1.14.0]# make
make install
[[email protected] nginx-1.14.0]# make install
nginx目录
[[email protected] nginx-1.14.0]# ls /usr/local/nginx/ ##目录
conf html logs sbin
[[email protected] 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
[[email protected] nginx-1.14.0]# ls /usr/local/nginx/html/ ##样例文件
50x.html index.html
[[email protected] nginx-1.14.0]# ls /usr/local/nginx/logs/ ##存放日志
[[email protected] nginx-1.14.0]# ls /usr/local/nginx/sbin/ ##他的进程核心的文件
nginx
-t也是支持的查询配置文件是否有错
[[email protected] 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创建配置文件还要给他做个启动脚本
[[email protected] 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里
改权限
[[email protected] nginx-1.14.0]# chmod 755 /etc/init.d/nginx
开机启动
[[email protected] nginx-1.14.0]# chkconfig --add nginx
[[email protected] nginx-1.14.0]# chkconfig nginx on
编辑配置文件这个配置文件需要下载模板
[[email protected] nginx-1.14.0]# cd /usr/local/nginx/conf/ ##进入配置文件
[[email protected] 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
[[email protected] conf]# mv nginx.conf nginx.conf.1 ##拷贝改名字
开始配置
[[email protected] 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;
}
}
}
[[email protected] 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
启动
[[email protected] conf]# /etc/init.d/nginx start
默认虚拟主机
Nginx用户认证
Nginx域名重定向
以上是关于46次课(Nginx安装 默认虚拟主机Nginx用户认证Nginx域名重定向)的主要内容,如果未能解决你的问题,请参考以下文章