nginx 安装和搭建网站

2019-09-28  本文已影响0人  a幕城

1.安装官方仓库源

[root@web 01 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://nginx.org/keys/nginx_signing.key

2.使用yum直接安装

[root@web 01 ~]#yum install nginx   -y

3.启动nginx

systemctl  start  nginx

4.配置了解一下

[root@web 01 ~]# cat /etc/nginx/nginx.conf
user nginx                          #用户身份
worker_processes  1;        #nginx的工作进程数量
error_log /var/log/nginx/error.log warn;  #错误的日志警告
pid  /var/run/nginx.pid;          #进程运行后,产生一个pid
events {                                         #事件模型
           worker_connections  1024;  #每个work能支持的连接数
            use epoll;                        #使用epoll网络模型
    }
http {
      收用户的http请求
     include   /etc/nginx/mime.types;    包含所有的静态资源文件
      default_type  application/octet-stream;      默认类型
  日志相关
log_format main '$remote_addr -$remote_user [$time_local] "$requst" '
        ' $status $body_bytes_sent "$http_referer" '
        ' "$http_user_agent" "$http_x_forwarded_for" ';
access_log /var/log/nginx/access.log main;    访问日志的路径
#sendfile    on;
#top_nopush   on;
keepalive_timeout  65;      长链接时间
#gzip  on;                      启用压缩功能

使用server配置网站,每个Server{}代表一个网站

server {
            listen 80;
            server_name  test.oldxu.com;
              
            location / {
                                 root .........
          }
}

Nginx搭建 游戏网站

1.注释掉之前的默认网站
[root@web01  html]#cd /etc/nginx/conf.d/
[root@web01 conf.d]#gzip default.conf
2.编写游戏网站Nginx配置文件
[root@web01 conf.d]#cat game.oldxu.conf
server {
              listen 80;
              server_name   game.oldxu.com;

               location / {
                                    root   /code
                                     index  index.html;
                    }
}

3.根据Nginx的配置文件,初始化

[root@web01 conf.d]#mkdir /code

4.上传代码

[root@web01 conf.d]#cd  /code/
[root@web01 code]# rz  html5.zip
[root@web01  code]# unzip html5.zip

5检测语法

[root@web01 code]#nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

6重启服务

[root@web01    code]# systemctl  restart   nginx
上一篇 下一篇

猜你喜欢

热点阅读