study forty-four

12.6 Nginx installation
12.7 Default virtual host
12.8 Nginx user authentication
12.9 Nginx domain name redirection

Extended
nginx.conf configuration details http://www.ha97.com/5194.html http://my.oschina.net/duxuefeng/blog/34880
nginx rewrite four flags http://www.netingcn.com/nginx -rewrite-flag.html http://unixman.blog.51cto.com/10163040/1711943

Nginx installation

cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd /usr/local/src/nginx-1.12. 1
./configure --prefix=/usr/local/nginx
make && make install
vim /etc/init.d/nginx //Copy the following (refer to https://coding.net/u/aminglinux/p/aminglinux- book/git/blob/master/D15Z/etc_init.d_nginx )
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 //Write the following content (refer to https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)
/usr/local/nginx /sbin/nginx -t
/etc/init.d/nginx start
netstat -lntp |grep 80
test php parsing
vi /usr/local/nginx/html/1.php //Add the following content
<?php
echo "test php scripts.";
?>
curl localhost/1.php

Default virtual host

vim /usr/local/nginx/conf/nginx.conf //Add
include vhost/*.conf
mkdir /usr/local/nginx/conf/vhost
cd !$;
vim default.conf //Add the following content
server
{
listen 80 default_server; // The one marked with this is the default virtual host
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
}
mkdir -p /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
curl localhost
curl -x127.0.0. 1:80 123.com

Nginx user authentication

vim /usr/local/nginx/conf/vhost/test.com.conf// write the following content
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
-t && -s reload //test Configure and reload
mkdir /data/wwwroot/test.com
echo “test.com” >
/data/wwwroot/test.com/index.html curl -x127.0.0.1:80 test.com -I//status code For 401, it means that you need to verify
curl -uaming:passwd and the access status code becomes 200

Edit the hosts file of Windows, and then visit test.com in the browser, there will be a pop-up window
for entering the user and password. User authentication for the directory
location /admin/
{
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/htpasswd ;
}

Nginx domain name redirection

change 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;
}
}
The server_name supports writing multiple domain names, here is a comparison with httpd's
permanent redirect, status The code is 301, and if you write redirect, it will be 302

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324793174&siteId=291194637