前言:
Nginx网站架构实战------01、Nginx介绍及编译安装:传送门
Nginx网站架构实战------02、Nginx信号量:传送门
基于域名访问 {#基于域名访问}
[sourcecode language="plain"]
[root@tiejiang nginx]# mkdir z.com #在nginx的家目录创建z.com文件夹
[root@tiejiang nginx]# vim z.com/index.html #在z.com里面创建一个默认首页
<html>
this is z.com
</html>
[root@tiejiang nginx]# vim conf/nginx.conf
server {
listen 80; #监听的端口
server_name z.com; #访问的地址
location / {
root z.com; #相对路径是nginx的根目录
index index.html; #访问z.com的默认页面
}
}
[root@tiejiang nginx]# ./sbin/nginx -s reload #重新加载一下配置文件
[/sourcecode]
基于端口访问 {#基于端口访问}
[sourcecode language="plain"]
[root@tiejiang nginx]# cat /var/www/html/index.html
<html>
wecome to z.com:8080 admin panel
</html>
[root@tiejiang nginx]# vim conf/nginx.conf
server {
listen 8080; #用的是8080的端口来访问
server_name 192.168.0.11; #访问的地址
location / {
root /var/www/html/; #网页程序的绝对路径
index index.html;
}
}
[root@tiejiang nginx]# ./sbin/nginx -s reload
[/sourcecode]