第一步:
cd /usr/local/nginx
第二步:找到conf文件 並且進入
輸入
ll
[root@Nigux nginx]# ll
總用量 4
drwxr-xr-x. 2 root root 4096 7月 28 01:39 conf
drwxr-xr-x. 2 root root 40 7月 28 01:39 html
drwxr-xr-x. 2 root root 19 7月 28 01:39 sbin
[root@Nigux nginx]# cd conf
[root@Nigux conf]# ll
總用量 60
-rw-r--r--. 1 root root 1034 7月 28 01:39 fastcgi.conf
-rw-r--r--. 1 root root 1034 7月 28 01:39 fastcgi.conf.default
-rw-r--r--. 1 root root 964 7月 28 01:39 fastcgi_params
-rw-r--r--. 1 root root 964 7月 28 01:39 fastcgi_params.default
-rw-r--r--. 1 root root 2837 7月 28 01:39 koi-utf
-rw-r--r--. 1 root root 2223 7月 28 01:39 koi-win
-rw-r--r--. 1 root root 3957 7月 28 01:39 mime.types
-rw-r--r--. 1 root root 3957 7月 28 01:39 mime.types.default
-rw-r--r--. 1 root root 2656 7月 28 01:39 nginx.conf
-rw-r--r--. 1 root root 2656 7月 28 01:39 nginx.conf.default
-rw-r--r--. 1 root root 596 7月 28 01:39 scgi_params
-rw-r--r--. 1 root root 596 7月 28 01:39 scgi_params.default
-rw-r--r--. 1 root root 623 7月 28 01:39 uwsgi_params
-rw-r--r--. 1 root root 623 7月 28 01:39 uwsgi_params.default
-rw-r--r--. 1 root root 3610 7月 28 01:39 win-utf
第三步:進入nginx.conf 配置文件
vim nginx.conf
找到這個節點
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
解釋一下
server 中 listen 80; 代表監控的80端口
root html; 代表 安裝程序所在的目錄
因爲我們把Nginx安裝在cd /usr/local/nginx/
目錄下的html 就是上面所指的本地的html
index index.html index.htm; 表示歡迎頁
也就是說 一個server 就是一個虛擬主機
通過配置不同的端口,實現不同的網站
接下來,我們要修改配置文件 下載一個好用的文本編輯器EditPlus
然後在左邊下拉框 選擇
完全實現在windows下修改 server
刪除一些帶#號註釋的部分 保存後 直接就能保存到服務端
接下來 我們只需要複製 server 修改其中的端口號就可以了
複製 一份 注意括號
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 81;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html81;
index index.html index.htm;
}
}
}
爲了區分 之前端口,和歡迎界面 我們改爲html81 但是跟目錄下並沒有html81
所以 在執行 本文中 第一步 cd /usr/local/nginx
如果複製目錄 我們就加 -r 如果要是複製文件 就直接cp
複製cp -r html html81
修改一下 這個html81 區分
命令
vim html81/index.html
進入編輯
<!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>
修改
修改完之後
我們要重新加載一下
[root@Nigux nginx]# sbin/nginx -s reload
測試 http://192.168.191.129/:80