[root@server ~]# yum -y install nginxhtml
[root@server ~]# vim /etc/nginx/nginx.confnginx
# line 38: 修改主機名vim
server_name www.example.com;服務器
[root@server ~]# systemctl start nginx ide
[root@server ~]# systemctl enable nginx測試
虛擬主機配置.網站
[root@server ~]# vim /etc/nginx/conf.d/virtual.host.conf雲計算
# 建立一個新文件spa
server {rest
listen 80;
server_name www.virtual.com;
location / {
root /usr/share/nginx/virtual.host;
index index.html index.htm;
}
}
[root@server ~]# mkdir /usr/share/nginx/virtual.host
[root@server ~]# systemctl restart nginx
[root@server ~]# vi /usr/share/nginx/virtual.host/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx Virtual Host Test Page
</div>
</body>
</html>
[root@server ~]# vim /etc/nginx/nginx.conf
# 添加到 "server" 章節
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
[root@server ~]# systemctl restart nginx
[jeffrey@server ~]$ chmod 711 /home/cent
[jeffrey@server ~]$ mkdir ~/public_html
[jeffrey@server ~]$ chmod 755 ~/public_html
[jeffrey@server ~]$ vi ~/public_html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>
[root@server ~]# vim /etc/nginx/nginx.conf
# 添加到"server" 部分
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
server_name www.example.com;
root /usr/share/nginx/html;
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/certs/server.key;
[root@server ~]# systemctl restart nginx
[root@server ~]# yum -y install httpd-tools
[root@server ~]# vim /etc/nginx/nginx.conf
# 添加到 "server" 部分
location /auth-basic {
auth_basic "Basic Auth";
auth_basic_user_file "/etc/nginx/.htpasswd";
}
[root@server ~]# htpasswd -c /etc/nginx/.htpasswd jeffrey
[root@client ~]# systemctl restart nginx