linux 添加重定向域名,Linux系统中Nginx的安装并进行域名认证和重定向

Linux系统中Nginx的安装并进行域名认证和重定向

本文主要介绍Linux系统中Nginx的安装并进行域名认证和重定向,希望通过本知识点的讲解对大家今后的学习和工作有所帮助,下面进行具体介绍:

12.6 Nginx安装

e14e84234ea9ee22554646b32b753337.pngcd /usr/local/src

wget http://nginx.org/download/nginx-1.8.0.tar.gz

tar zxvf nginx-1.8.0.tar.gz

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

make && make install

查看配置文件是否有错 -t

/usr/local/nginx/sbin/nginx -t

启动脚本编辑:

vim /etc/init.d/nginx //复制如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx)

内容为

--------------------------------------------------------------echo#!/bin/bash

# chkconfig: - 30 21

# description: http service.

# Source Function Library

. /etc/init.d/functions

# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"

NGINX_CONF="/usr/local/nginx/conf/nginx.conf"

NGINX_PID="/usr/local/nginx/logs/nginx.pid"

RETVAL=0

prog="Nginx"

start()

{

echo -n $"Starting $prog: "

mkdir -p /dev/shm/nginx_temp

daemon $NGINX_SBIN -c $NGINX_CONF

RETVAL=$?

echo

return $RETVAL

}

stop()

{

echo -n $"Stopping $prog: "

killproc -p $NGINX_PID $NGINX_SBIN -TERM

rm -rf /dev/shm/nginx_temp

RETVAL=$?

return $RETVAL

}

reload()

{

echo -n $"Reloading $prog: "

killproc -p $NGINX_PID $NGINX_SBIN -HUP

RETVAL=$?

echo

return $RETVAL

}

restart()

{

stop

start

}

configtest()

{

$NGINX_SBIN -c $NGINX_CONF -t

return 0

}

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

restart

;;

configtest)

configtest

;;

*)

echo $"Usage: $0 {start|stop|reload|restart|configtest}"

RETVAL=1

esac

exit $RETVAL

--------------------------------------------------------------

chmod 755 /etc/init.d/nginx

chkconfig --add nginx

chkconfig nginx on

cd /usr/local/nginx/conf/;mv nginx.conf nginx.conf.bak

vim nginx.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/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;

}

}

}

--------------------------------------------------------------

/usr/local/nginx/sbin/nginx -t

/etc/init.d/nginx start

ps aux | grep nginx

netstat -lntp | grep 80

测试#curl localhost

测试php

vim /usr/local/nginx/html/1.php

写入以下内容

----------------------------------------------------------------

echo "This is nginx test page";

----------------------------------------------------------------

测试curl localhost/1.php

12.7 默认虚拟主机

f89a8069a58f62f69987dd43d8ca6526.png

vim /usr/local/nginx/conf/nginx.conf //http里增加下面一行

include vhost/*.conf;

mkdir /usr/local/nginx/conf/vhost

cd !$;vim default.conf //加入如下内容

----------------------------------------------------------------

server

{

listen 80 default_server; //有这个标记的就是默认虚拟主机

server_name aaa.com;

index index.html index.htm index.php;

root /data/wwwroot/default;

}

----------------------------------------------------------------

mkdir -p /data/wwwroot/default

cd /data/wwwroot/default

echo "This is a default site." > /data/wwwroot/default/index.html

/usr/local/nginx/sbin/nginx -t //检查配置是否有错

/usr/local/nginx/sbin/nginx -s reload //重新加载,也可以重启服务

或/etc/init.d/nginx restart //重启服务

curl localhost

curl -x127.0.0.1:80 123.com

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;

}

}

----------------------------------------------------------------

yum install -y httpd

htpasswd -c /usr/local/nginx/conf/htpasswd aming //-c创建

/usr/local/nginx/sbin/nginx -t //检查配置是否有错

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

curl -x127.0.0.1:80 test.com -I

curl -uaming:lishiming -x127.0.0.1:80 test.com //404错误,-u指定用户;

ls /data/wwwroot/test.com

mkdir /data/wwwroot/test.com

echo "test.com" > /data/wwwroot/test.com/index.html

curl -uaming:lishiming -x127.0.0.1:80 test.com

指定访问admin才认证

curl -uaming:lishiming -x127.0.0.1:80 test.com/admin/

vim /usr/local/nginx/conf/vhost/test.com.conf

将location /修改为location /admin/即可;

curl -x127.0.0.1:80 test.com  //就不用指定用户了;

curl -x127.0.0.1:80 test.com/admin/  //提示401用户请求

12.9 Nginx域名重定向

vim /usr/local/nginx/conf/vhost/test.com.conf //修改为如下内容

----------------------------------------------------------------

server

{

listen 80 ;

server_name test.com  test1.com   test2.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

if($host!='test.com'){

rewrite ^/(.*)$ http://test.com/$1 permanent;

}

location ~ admin.php

{auth_basic              "Auth";

auth_basic_user_file /usr/local/nginx/conf/htpasswd;

}

}

----------------------------------------------------------------

^表示以某某开头,这里指http://$host

(.*)表示通配所有,$表示直到结尾;

/usr/local/nginx/sbin/nginx -t //检查配置是否有错

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

curl -x127.0.0.1:80 test2.com/index.html -I //提示301,都重定向到test.com/index.html网页;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/567871.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C/C++混淆点-转义字符

从表中可以看出,在C语言中有三种转义字符,它们是:一般转义字符、八进制转义字符和十六进制转义字符。 所有的转义字符只代表一个字符 1. 一般转义字符 这种转义字符,虽然在形式上由两个字符组成,但只代表一个字符。…

linux如何安装python环境变量中,Windows和linux环境下python安装及环境变量的配置

安装包的安装无需双版本存在情况下安装1)下载源码包2)解压源码包并进入文件夹./configure ; make && make install3)使用python -V查看是否安装成功,安装成功会显示python版本信息需要双版本安装python版本1)同上,需要下载3.6源码包2)解压源码包…

C/C++混淆点-strcat和strcpy区别

一、原因分析 假设: char * strNULL; strnew char[11];你想为字符串str开辟一个存储十个字符的内存空间,然后你现在有两个字符串:char * c1"abc"和char * c2"123";你想将这两个字符串都拼接在str字符串中,你…

linux有读EC RAM的工具吗,Step to UEFI (179)Shell下 EC Ram 读取工具

最近工作需要在 UEFI Shell 下Check EC Ram 的设定,发现手上只有 Windows 下的读取工具(RW Everything)。于是研究了一下如何在Shell 读取 EC Ram。根据【参考1】读取的流程如下:Port 66 CommandsThere are also some EC commands that use ports 0x66 …

C++基础13-类和对象之继承1

在 C中可重用性(software reusability)是通过继承(inheritance)这一机制来实现的。 如果没有掌握继承性,就没有掌握类与对象的精华。 总结: 1、只要是父类中的private成员,不管是什么继承方式,儿子都访问不了,但它是存在在儿子之…

线程锁定CPU linux,linux 线程与CPU绑定

看到很多程序都是根据CPU个数来创建线程个数,当时很不理解他们之间的关系,请教了项目组的同事后才有了大致了解。1. 相关系统函数下面的函数可以通过man命令查询到。SYNOPSIS#define _GNU_SOURCE#include int pthread_setaffinity_np(pthread_t thread, …

C++基础13-类和对象之继承2

总结: 1、子类对象可以当做父类对象使用 2、子类对象可以直接赋值给父类对象 3、子类对象能够直接初始化父类对象 4、父类指针可以直接指向子类对象 5、凡是继承过来的属性和函数都可以在子类中用this-> 进行访问 6、默认构造函数并不会初始化数据成员 7、如果…

linux内核 块驱动程序,linux – 为什么内核使用默认的块驱动程序而不是我的驱动程序代码?...

我写了一个块驱动程序,它创建了一个虚拟块设备(sbd0).我为该块设备注册了所有设备操作:(请参阅2.6.32内核源代码中的include /linux / blkdev.h)static struct block_device_operations sbd_ops {.owner THIS_MODULE,.open sbd_open,.release sbd_close,.ioctl sbd_ioctl,…

C++基础14-类和对象之多继承与虚继承

多继承:一个类有多个直接基类的继承关系称为多继承 总结: 1、一般将具有菱形样式继承方式的某些类声明为虚继承 3、虚继承的主要目的是为了防止二义性 2、虚继承就是在继承方式前加virtual 如果一个派生类从多个基类派生,而这些基类又有一…

linux系统安装ntp,CentOS下NTP安装配置

安装yum install ntp配置文件 /etc/ntp.confrestrict default kod nomodifynotrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict -6 ::1# 用restrict控管权限# nomodify - 用户端不能更改ntp服务器的时间参数# noquery - …

C++基础15-类和对象之多态

总结: 1、在父类中申明虚函数时,一般情况下在子类中也申明(便于读代码) 一、赋值兼容 赋值兼容规则是指在需要基类对象的任何地方都可以使用公有派生类的对象来替代。 赋值兼容是一种默认行为,不需要任何的显示的转化步骤。 …

傲云浏览器linux,Centos7安装部署zabbix监控软件

目录部署监控服务器部署监控服务器Zabbix ServerWeb页面验证设置部署监控服务器一、安装LNMP环境Zabbix监控管理控制台需要通过Web页面展示出来,并且还需要使用MySQL来存储数据,因此需要先为Zabbix准备基础LNMP环境。1. wget下载官网Nginxwget http://ng…

C++基础16-类和对象之联编,重写,虚析构

1、静态联编和动态联编 1、联编是指一个程序模块、代码之间互相关联的过程。 2、静态联编(sta5c binding),是程序的匹配、连接在编译阶段实现,也称为早期匹配。重载函数使用静态联编。 3、动态联编是指程序联编推迟到运行时…

c语言环境变量的作用,C语言获取系统环境变量

C语言获取系统环境变量可以通过如下代码实现.#include #include char *platform(){//获取系统变量信息char *ret;extern char **environ;char **env environ;//打印系统变量信息/*while(*env){//puts(*env);env;}*/ret getenv("OS"); //for windows_ntif(NULL ! re…

C++基础17-纯虚函数和抽象类

总结: 1,含有纯虚函数的类,称为抽象基类,不可实列化。即不能创建对象,存在 的意义就是被继承,提供族类的公共接口。 2,纯虚函数只有声明,没有实现,被“初始化”为 0。 3,如果一个类中声明了纯虚函数,而在派生类中没有对该函数定义,则该虚函数在派生类中仍然为纯…

c语言wpf99乘法表,使用JSP输出九九乘法表

R数据实战vehicles--1新建项目vehicles-project 数据文件vehicles.csv与varlabels.txt放在项目文件中【CSS3】---颜色RGBA及渐变色颜色之RGBA RGB是一种色彩标准,是由红(R).绿(G).蓝(B)的变化以及相互叠加来得到各式各样的颜色.RGBA是在RGB的基础上增加了控制alpha透明度的参数…

C++基础18-抽象类-电脑组装练习

01电脑组装me.cpp 需要实现所有的虚函数&#xff0c;不台灵活。架构函数无法写&#xff0c;设计不够成熟 #if 1 #include<iostream> using namespace std; class Computer { public:virtual void caculate() 0;virtual void display() 0;virtual void storage() 0; …

以串结构存储c语言版,数据结构C语言版 串的块链存储表示和实现

《数据结构C语言版 串的块链存储表示和实现》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《数据结构C语言版 串的块链存储表示和实现(13页珍藏版)》请在人人文库网上搜索。1、*数据结构C语言版 串的块链存储表示和实现P78编译环境&#xff1a;Dev-C 4.9.9.2日期&…

mysql索引创建及使用注意事项

总结&#xff1a; 1、在使用索引时&#xff0c;一般情况下不建议使用like操作。如果使用&#xff0c;则%放在后面。否则不会使用索引。like ‘%abd%’不会使用索引,而like ‘aaa%’可以使用索引.&#xff08;最左缀原则&#xff09; 2、单列索引的使用&#xff1a; 《1》 只…

mulitpartfile怎么接收不到值_和平精英信号接收区和信号值是什么?信号值怎么恢复...

[闽南网]和平精英公测开启&#xff0c;和平精英与刺激战场有什么不同呢&#xff1f;今天小编就为大家带来了信号值详解&#xff01;各位玩家千万不要错过呀&#xff01;信号值详解信号接收区和信号值是什么&#xff0c;对选手有什么影响&#xff1f;在游戏战斗界面中&#xff0…