在编译安装的nginx里部署网站

1、修改配置文件

cd /usr/local/nginx-1/conf
vim nginx.conf

#user  nobody;
#woker进程数(与cpu核数相同)
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


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 就是一个网站
    #一个server就是一个虚拟主机(网站)
    server {
	#网站监听的端口
        listen       80;
        #网站对应的域名
        server_name  www.scweb.com;

        #charset koi8-r;
	#定义访问日志的路径和名字、记录的内容
        access_log  logs/scweb.access.log  main;
        #定义错误日志:访问网站出错的时候,服务器会记录下来
        error_log  logs/scweb.error.log
	#定义路由  / 网站根目录
        location / {
	    #定义网站存放网页的文件夹--》网站内容根目录 --》在/usr/local/nginx-1/html
            root   html;  
            index  index.html index.htm  shouye.html;
        }

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

2、测试nginx.conf配置文件是否有语法错误,并重启nginx

nginx -t
nginx -s reload

3、进入存放网站的目录,修改index.html网页

cd /usr/local/nginx-1/html
vim index.html

<!DOCTYPE html>
<html>
<head>
<title>Welcome to scweb</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to scweb!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

访问测试
修改hosts文件

vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.205.135  www.scweb.com

访问网站

curl www.scweb.com

在这里插入图片描述

在一个nginx服务器里部署多个网站
在nginx配置文件中添加信息

vim /usr/local/nginx-1/conf/nginx.conf

server {
        listen       80; #监听端口号
        server_name  www.feng.com; #域名
        access_log   logs/feng.com.access.log; # 访问日志
        error_log    logs/feng.com.error.log; # 错误日志
        location / {
            root   html/feng;# 网站首页
            index  index.html index.htm;
        }
    }

    server {
        listen       80;
        server_name  www.wen.com;
        access_log   logs/wen.com.access.log;
        error_log    logs/wen.com.error.log;
        location / {
            root   html/wen;
            index  index.html index.htm;
        }
    }

检查配置文件是否没有语法错误

nginx -t

进入html文件夹中新建feng和wen文件夹

cd html
mkdir feng
mkdir wen

分别给feng和wen创建首页index.html

cd feng
 
vim index.html
welcome to feng's website
cd wen

vim index.html
welcome to wen's website

重启nginx服务

nginx -s reload

接下来,进行访问测试
修改hosts文件

vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.205.135  www.scweb.com
192.168.205.135  www.feng.com
192.168.205.135  www.wen.com

访问网站

curl www.feng.com

curl www.wen.com

在这里插入图片描述

扩展:conf配置文件的一些功能模块

  • 隐藏nginx的版本
    在这里插入图片描述
  • 提供下载功能
    在这里插入图片描述
  • 开启状态统计功能
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值