開始編譯
查看Nginx目錄下的東西

[root@aminglinux-02 nginx-1.12.1]# ls /usr/local/nginx/ conf html logs sbin

配置文件目錄

[root@aminglinux-02 nginx-1.12.1]# ls /usr/local/nginx/conf/ fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default fastcgi_params koi-win nginx.conf scgi_params.default win-utf

樣例目錄

[root@aminglinux-02 nginx-1.12.1]# ls /usr/local/nginx/html/ 50x.html index.html

日志目錄

[root@aminglinux-02 nginx-1.12.1]# ls /usr/local/nginx/logs/

核心進程目錄

[root@aminglinux-02 nginx-1.12.1]# ls /usr/local/nginx/sbin/ nginx

支持-t 檢查語法錯誤

[root@aminglinux-02 nginx-1.12.1]# /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創建啟動腳本

vim /etc/init.d/nginx

啟動腳本內容如下:

#!/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=$? echo 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

更改配置文件權限

[root@aminglinux-02 nginx-1.12.1]# chmod 755 !$ chmod 755 /etc/init.d/nginx

將nginx加入到服務列表里

chkconfig –add nginx

配置開啟啟動nginx服務

chkconfig nginx on

定義配置文件 默認conf目錄下是有一個配置文件的,但是我們用自己的配置

[root@aminglinux-02 conf]# ls fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default fastcgi_params koi-win nginx.conf scgi_params.default win-utf [root@aminglinux-02 conf]# mv nginx.conf nginx.conf.old [root@aminglinux-02 conf]# ls fastcgi.conf fastcgi_params.default mime.types nginx.conf.old uwsgi_params fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default fastcgi_params koi-win nginx.conf.default scgi_params.default win-utf

創建一個配置文件

[root@aminglinux-02 conf]# vim 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; //使用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 //一個server 對應一個虛擬主機,定義這個,才能正常訪問網站 下面一整段,就是一個默認的虛擬主機 { listen 80; server_name localhost; //網站域名 index index.html index.htm index.php; root /usr/local/nginx/html; //網站的根目錄 location ~ .php$ //配置解析php的部分 { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; //nginx通過這一行配置來調用php-fpm服務 fastcgi_pass 127.0.0.1:9000; //如果php-fpm監聽的是9000端口,直接這樣寫配置即可 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } }

作為一個網站的服務,必須監聽一個端口,默認監聽的是80端口,假如沒有配置 server 這個幾行,那么nginx將識別不到監聽端口,導致服務不可用
編譯好配置,就使用 -t 檢查一下是否有錯

[root@aminglinux-02 conf]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok // /usr/local/nginx/conf/nginx. nginx:配置文件配置語法好 nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful // /usr/local/nginx/conf/nginx. nginx:配置文件配置測試是成功的

啟動服務

[root@aminglinux-02 nginx]# service nginx start Starting nginx (via systemctl): Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. [失敗]

提示出錯
之后嘗試執行提示的命令 “systemctl status nginx.service ”

[root@aminglinux-02 111]# systemctl status nginx.service ● nginx.service – SYSV: http service. Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled) Active: failed (Result: exit-code) since 四 2017-08-10 21:26:30 CST; 46s ago Docs: man:systemd-sysv-generator(8) Process: 6541 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE) 8月 10 21:26:28 aminglinux-02 nginx[6541]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 10 21:26:28 aminglinux-02 nginx[6541]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 10 21:26:29 aminglinux-02 nginx[6541]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 10 21:26:29 aminglinux-02 nginx[6541]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 8月 10 21:26:30 aminglinux-02 nginx[6541]: nginx: [emerg] still could not bind() 8月 10 21:26:30 aminglinux-02 nginx[6541]: [失敗] 8月 10 21:26:30 aminglinux-02 systemd[1]: nginx.service: control process exited, code=exited status=1 8月 10 21:26:30 aminglinux-02 systemd[1]: Failed to start SYSV: http service.. 8月 10 21:26:30 aminglinux-02 systemd[1]: Unit nginx.service entered failed state. 8月 10 21:26:30 aminglinux-02 systemd[1]: nginx.service failed. Warning: nginx.service changed on disk. Run \\\’systemctl daemon-reload\\\’ to reload units.

提示端口已經被占用
查看端口

[root@aminglinux-02 111]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4849/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1236/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2076/master tcp6 0 0 :::3306 :::* LISTEN 1691/mysqld tcp6 0 0 :::22 :::* LISTEN 1236/sshd tcp6 0 0 ::1:25 :::* LISTEN 2076/master

發現占用端口的就是nginx本身
只能“殺掉 ”nginx程序再試

root@aminglinux-02 111]# killall nginx [root@aminglinux-02 111]# /etc/init.d/nginx start Starting nginx (via systemctl): Warning: nginx.service changed on disk. Run \\\’systemctl daemon-reload\\\’ to reload units. [ 確定 ] [root@aminglinux-02 111]# ps aux |grep nginx root 6623 0.0 0.0 20484 624 ? Ss 21:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 6624 0.0 0.1 22928 3216 ? S 21:32 0:00 nginx: worker process nobody 6625 0.0 0.1 22928 3216 ? S 21:32 0:00 nginx: worker process root 6628 0.0 0.0 112664 976 pts/1 R 21:35 0:00 grep –color=auto nginx

這時發現啟動成功了
但是有警告提示
再次執行提示的命令“systemctl daemon-reload ”

[root@aminglinux-02 111]# systemctl daemon-reload [root@aminglinux-02 111]# service nginx stop Stopping nginx (via systemctl): [ 確定 ] [root@aminglinux-02 111]# service nginx start Starting nginx (via systemctl): [ 確定 ] [root@aminglinux-02 111]#

這下就正常了

啟動完成以后看一下進程

[root@aminglinux-02 111]# ps aux |grep nginx root 6762 0.0 0.0 20484 624 ? Ss 21:45 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 6763 0.0 0.1 22928 3212 ? S 21:45 0:00 nginx: worker process nobody 6764 0.0 0.1 22928 3212 ? S 21:45 0:00 nginx: worker process root 6769 0.0 0.0 112664 972 pts/1 R 21:55 0:00 grep –color=auto nginx

測試一下訪問情況

[root@aminglinux-02 ~]# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>

測試一下是否支持PHP解析

[root@aminglinux-02 ~]# curl localhost/1.php This is nginx test page.[root@aminglinux-02 ~]# [root@aminglinux-02 ~]# vim /usr/local/nginx/html/1.php [root@aminglinux-02 ~]# curl -x127.0.0.1:80 localhost/1.php -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 16:15:02 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30

返回碼是200 證明是通的

12.7 默認虛擬主機

修改nginx.cnf配置,刪除默認的虛擬主機配置,重新定義虛擬主機配置所在路徑

[root@aminglinux-02 default]#vim /usr/local/nginx/conf/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; include vhost/*.conf; //新增這一行,定義默認虛擬主機的目錄 }

第一次配置的時候,出現提示 “ } ”這個所在行語法錯誤,一直找不到原因,最后重新粘貼配置文件以后,發現只是新增的“include vhost/*.conf ”配置最后沒有添加“ ; ”分號結尾。

創建虛擬主機的目錄

[root@aminglinux-02 conf]# pwd /usr/local/nginx/conf [root@aminglinux-02 conf]# mkdir vhost [root@aminglinux-02 conf]# ls fastcgi.conf fastcgi_params.default mime.types nginx.conf.default scgi_params.default vhost fastcgi.conf.default koi-utf mime.types.default nginx.conf.old uwsgi_params win-utf fastcgi_params koi-win nginx.conf scgi_params uwsgi_params.default 定義新增虛擬主機的配置 [root@aminglinux-02 conf]# cd vhost/ [root@aminglinux-02 vhost]# pwd /usr/local/nginx/conf/vhost server { listen 80 default_server; //有這個“default_server ”就是表示這是一個默認虛擬主機 server_name aaa.com; //指定主機名 index index.html index.htm index.php; //指定索引頁 root /data/wwwroot/default; //指定root的目錄 }

創建網站的根目錄

[root@aminglinux-02 vhost]# mkdir /data/wwwroot [root@aminglinux-02 vhost]# mkdir /data/wwwroot/default [root@aminglinux-02 vhost]# cd !$ cd /data/wwwroot/default [root@aminglinux-02 default]# ls

在“/data/wwwroot/default “下創建索引頁

[root@aminglinux-02 default]# vim index.html This is the default site.

編輯好之后檢查一下是否有語法的錯誤

[root@aminglinux-02 default]# /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服務(更改配置文件以后,要重新加載或者重啟一下服務)

[root@aminglinux-02 default]# /usr/local/nginx/sbin/nginx -s reload

測試一下訪問默認頁

[root@aminglinux-02 default]# curl localhost This is the default site. [root@aminglinux-02 default]# ls index.html

因為修改了nginx.conf的配置,現在看到的默認索引頁,是我們剛剛新增的vhost的虛擬主機的索引頁了

定義默認虛擬主機的兩種辦法:

默認虛擬主機,是根據目錄的第一個.conf了進行選擇,所以只需要在vhost目錄下依次創建就可以了,當然這種方法不智能 只需要在vhost目錄的.conf配置文件內,加上一個“default_server ”即可,把當前的這個配置對應的網站設置為第一個默認虛擬主機 12.8 Nginx用戶認證

配置Nginx用戶認證
新建一個虛擬主機配置文件

[root@aminglinux-02 vhost]# vim test.com.conf server { listen 80 ; server_name test.com; index index.html index.htm index.php; root /data/wwwroot/test.com; location / //表示全站,都需要進行用戶認證 #location /admin // 這個地方只要加上" /admin " 就變成 針對這個站點的“admin” 這個目錄需要用戶認證 #location ~ admin.php //如果把這行這樣寫,就會變成,匹配 “ admin.php ”這個頁面的時候才需要用戶認證 { auth_basic "Auth"; //定義用戶認證的名字 auth_basic_user_file /usr/local/nginx/conf/htpasswd; //用戶名、密碼文件 } }

虛擬機創建好之后,創建所需的目錄及文件

[root@aminglinux-02 vhost]# cd /data/wwwroot/ [root@aminglinux-02 wwwroot]# ls default [root@aminglinux-02 wwwroot]# mkdir test.com [root@aminglinux-02 wwwroot]# ls default test.com [root@aminglinux-02 test.com]# vim index.html test.com

配置弄好了,需要生產密碼文件
需要用到Apache生成密碼文件的工具“ htpasswd ”
兩種情況: 1.如果本機安裝有Apache,可以直接到所在目錄運行htpasswd進行生成 2.如果沒有安裝,直接“ yum install -y httpd ”安裝,因為yum安裝的,所以工具存放在/usr/bin/下,可以直接使用htpasswd

生成密碼文件

[root@aminglinux-02 vhost]# htpasswd -c /usr/local/nginx/conf/htpasswd aming New : Adding password for user aming [root@aminglinux-02 vhost]# cat /usr/local/nginx/conf/htpasswd aming:$apr1$45TTsuN4$9sOnkf8GUOVuCoWI2PcyL/

==關于htpasswd -c 命令 第一次創建的時候因為沒有htpasswd這個文件,需要-c創建,第二使用的時候因為已經有這個htpasswd文件了,將不再需要-c 選項,如果還繼續使用-c 這個選項,將會重置 htpasswd里的東西==

測試-c 是否會重置htpasswd文件

[root@aminglinux-02 vhost]# htpasswd -c /usr/local/nginx/conf/htpasswd user1 New : Adding password for user user1 [root@aminglinux-02 vhost]# !cat cat /usr/local/nginx/conf/htpasswd user1:$apr1$I/VKfzgJ$KTWtCG4aZhrvLU69tgvhl1 [root@aminglinux-02 vhost]# htpasswd /usr/local/nginx/conf/htpasswd aming New : Adding password for user aming [root@aminglinux-02 vhost]# !cat cat /usr/local/nginx/conf/htpasswd user1:$apr1$I/VKfzgJ$KTWtCG4aZhrvLU69tgvhl1 aming:$apr1$idtTK3wd$RLibX1IYqH1x.rc6VibVg1

測試一下語法

[root@aminglinux-02 vhost]# /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

重新加載服務

[root@aminglinux-02 vhost]# /usr/local/nginx/sbin/nginx -s reload

==重新加載服務的好處在于,如果配置里面出錯,將不會生效;如果是直接使用restart,如果配置有錯,將會直接影響到網站的運行==

測試 location / 針對整個站點進行用戶認證

因為修改配置的時候做的配置,就是針對整個站點配置的,直接對域名進行curl即可

[root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test.com -I HTTP/1.1 401 Unauthorized Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:33:37 GMT Content-Type: text/html Content-Length: 195 Connection: keep-alive WWW-Authenticate: Basic realm="Auth"

提示錯誤碼401,需要進行認證,認證方式 Basic realm="Auth"

使用指定用戶測試

[root@aminglinux-02 test.com]# curl -x127.0.0.1:80 -uaming:123123 test.com -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:36:04 GMT Content-Type: text/html Content-Length: 9 Last-Modified: Thu, 10 Aug 2017 17:35:22 GMT Connection: keep-alive ETag: "598c995a-9" Accept-Ranges: bytes 測試 location /admin 針對目錄

修改test.com.conf

location /

更改為

location /admin

到站點目錄下加創建一個admin 的目錄,為了方便測試,創建一測試頁

[root@aminglinux-02 test.com]# pwd /data/wwwroot/test.com [root@aminglinux-02 test.com]# mkdir admin [root@aminglinux-02 test.com]# ls 1.html admin index.html [root@aminglinux-02 test.com]# echo "admin–>test.com–>auth" > admin/login.php [root@aminglinux-02 test.com]# cat admin/login.php admin–>test.com–>auth [root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test.com/admin/login.php -I HTTP/1.1 401 Unauthorized Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:43:44 GMT Content-Type: text/html Content-Length: 195 Connection: keep-alive WWW-Authenticate: Basic realm="Auth" [root@aminglinux-02 test.com]# curl -x127.0.0.1:80 -uaming:123123 test.com/admin/login.php -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:44:26 GMT Content-Type: application/octet-stream Content-Length: 24 Last-Modified: Thu, 10 Aug 2017 17:41:45 GMT Connection: keep-alive ETag: "598c9ad9-18" Accept-Ranges: bytes 測試 location ~ 1.html 針對固定的URL

修改test.com.conf

location /admin

更改為

location ~ 1.html

創建所需的1.html

[root@aminglinux-02 test.com]# pwd /data/wwwroot/test.com [root@aminglinux-02 test.com]# vim 1.html This is the default site. test.com [root@aminglinux-02 test.com]# ls 1.html admin index.html [root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test.com/1.html -I HTTP/1.1 401 Unauthorized Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:50:19 GMT Content-Type: text/html Content-Length: 195 Connection: keep-alive WWW-Authenticate: Basic realm="Auth" [root@aminglinux-02 test.com]# curl -x127.0.0.1:80 -uaming:123123 test.com/1.html -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 17:50:42 GMT Content-Type: text/html Content-Length: 35 Last-Modified: Thu, 10 Aug 2017 16:57:21 GMT Connection: keep-alive ETag: "598c9071-23" Accept-Ranges: bytes 12.9 Nginx域名重定向

在Nginx里“ server_name ” 支持跟多個域名;但是Apache“ server_name ”只能跟一個域名,需要跟多個域名,需要使用Alisa
在Nginx的conf配置文件里“server_name ” 設置了多個域名,就會使網站的權重變了,到底需要哪個域名為主站點呢
所以需要域名重定向
更改配置“test.com.conf ”文件

server { listen 80 ; server_name test.com; index index.html index.htm index.php; root /data/wwwroot/test.com; if ($host != \\\’test.com\\\’ ) //假如域名,“!=”不等于 test.com,將執行下面的腳本 { rewrite ^/(.*)$ http://test.com/$1 permanent; // ^/(.*)$ 正式寫法 http://$host/(.*)$ 這段可以直接省略掉的,同時還可以加上一些規則,“ permanent ”就是301的意思;如果想弄成302,只需要更改為“ redirect ” } location ~ 1.html { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd; } }

改好配置,檢查語法,重新加載服務

[root@aminglinux-02 test.com]# /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 (reverse-i-search)`s\\\’: /usr/local/nginx/^Cin/nginx -t [root@aminglinux-02 test.com]# /usr/local/nginx/sbin/nginx -s reload

測試test2.com/index.html的跳轉情況

[root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test2.com/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 18:05:41 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/index.html

可以查看到 location 到了“ http://test.com/index.html ”

測試test3.com/index.html的跳轉情況

[root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test3.com/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 18:07:42 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/index.html [root@aminglinux-02 test.com]# curl -x127.0.0.1:80 test3.com/admin/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 10 Aug 2017 18:07:52 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/admin/index.html

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:www.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » 12.6 Nginx安裝 12.7 默認虛擬主機 12.8 Nginx用戶認證12.9 Nginx域名重定向

登錄

找回密碼

注冊