第一步:
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/
image.PNG
目录下的 HTML 就是上面所指的本地的 HTML
index index.HTML index.htm; 表示欢迎页
image.PNG
也就是说 一个 server 就是一个虚拟主机
通过配置不同的端口, 实现不同的网站
接下来, 我们要修改配置文件 下载一个好用的文本编辑器 EditPlus
image.PNG
image.PNG
然后在左边下拉框 选择
image.PNG
完全实现在 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
image.PNG
修改一下 这个 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>
修改
image.PNG
修改完之后
我们要重新加载一下
[root@Nigux nginx]# sbin/nginx -s reload
测试 http://192.168.191.129/:80
image.PNG
测试 http://192.168.191.129:81/
image.PNG
来源: http://www.jianshu.com/p/ded67c63df3b