日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php nginx 域名重定向,Nginx默认虚拟主机、用户认证、域名重定向

發布時間:2023/12/2 php 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php nginx 域名重定向,Nginx默认虚拟主机、用户认证、域名重定向 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Nginx默認虛擬主機定義默認虛擬主機配置文件,在http下面加入include vhost/*.conf

在/usr/local/nginx/conf/下創建目錄

#mkdir vhost/ //創建vhost目錄

#cd 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;

}

#mkdir /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 //重新加載nginx

#curl -x127.0.0.1:80 aaa.com //測試

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; //密碼所在的位置文件

}

}

htpasswd是apache的一個工具,該工具主要用于建立和更新存儲用戶名、密碼的文本文件,主要用于對基于http用戶的認證。htpasswd的安裝很簡單,它是隨apache的安裝而生成。

#yum install -y httpd //下載httpd包

#htpasswd -c /usr/local/nginx/conf/htpasswd zenwen //生成密碼文件

#/usr/local/nginx/sbin/nginx -t && -s reload //測試配置并重新加載

#mkdir /data/wwwroot/test.com //創建目錄

#echo “test.com”>/data/wwwroot/test.com/index.html

#curl -x127.0.0.1:80 test.com -I //狀態碼為401說明需要驗證

#curl -uzenwen:passwd -x127.0.0.1:80 test.com -I // 訪問狀態碼變為200

針對目錄的用戶認證

當訪問admin時,只需要在location /加上admin目錄就可以對admin進行用戶的驗證

location /admin/

{

auth_basic "Auth";

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

}

nginx域名重定向

更改test.com.conf

server{

listen 80;

server_name test.comtest1.comtest2.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

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

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

}

}

server_name后面支持寫多個域名,這里要和httpd做一個對比

permanent為永久重定向,狀態碼為301,如果寫redirect則為302

#/usr/local/nginx/sbin/nginx -t //檢測語法

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

#curl -x127.0.0.1:80 test2.com/index.html -I //測試

HTTP/1.1 301 Moved Permanently

Server: nginx/1.12.1

Date: Wed, 03 Jan 2018 02:45:07 GMT

Content-Type: text/html

Content-Length: 185

Connection: keep-alive

Location: http://test.com/index.html //直接重定向到了test.com

#curl -x127.0.0.1:80 test1.com/index.html -I //顯示狀態碼為301

HTTP/1.1 301 Moved Permanently

Server: nginx/1.12.1

Date: Wed, 03 Jan 2018 06:53:13 GMT

Content-Type: text/html

Content-Length: 185

Connection: keep-alive

Location: http://test.com/index.html

下面關于Nginx的文章您也可能喜歡,不妨參考下:

Nginx 的詳細介紹:請點這里

Nginx 的下載地址:請點這里

總結

以上是生活随笔為你收集整理的php nginx 域名重定向,Nginx默认虚拟主机、用户认证、域名重定向的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。