Linux(二)搭建Nginx服务器

2021-03-10  本文已影响0人  枫叶丶落

系统环境:Centos 7.0

1.下载相关包

> yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel  
> mkdir /usr/local/nginx  
> cd /usr/local/nginx
> wget http://nginx.org/download/nginx-1.13.7.tar.gz
> tar -xvf nginx-1.13.7.tar.gz

3.安装nginx

> cd nginx-1.13.7
> ./configure
> make
> make install

4.配置nginx.conf

> vi /usr/local/nginx/conf/nginx.conf  # 编译配置文件
#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
   worker_connections  1024;
}


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;  # 修改这里 对应的是端口号,默认的端口是80
       server_name  localhost; #  # 修改这里 对应的是ip,默认的是本地的

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

       # proxy the PHP scripts to Apache listening on 127.0.0.1:80
       #
       #location ~ \.php$ {
"nginx.conf" 117L, 2664C

4.启动nginx服务

> /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
> /usr/local/nginx/sbin/nginx -s reload  # 启动nginx服务
> systemctl stop firewalld.service
> ps -ef | grep nginx
         root      4460     1  0 19:30 ?       00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -                        
         c /usr/local/nginx/conf/nginx.conf
         nobody    5123  4460  0 19:33 ?        00:00:00 nginx: worker process
         root     11075 11759  0 20:05 pts/0    00:00:00 vi nginx.conf
         root     11529 11759  0 20:08 pts/0    00:00:00 vi //usr/local/nginx/conf
         root     11654 11759  0 20:08 pts/0    00:00:00 vi nginx.conf
         root     13807 11759  0 20:20 pts/0    00:00:00 grep --color=auto nginx
> cd /usr/local/nginx/sbin  # 进入此文件夹
> ./nginx  # 启动nginx服务
> ./nginx -s stop  # 关闭nginx服务
> ./nginx -s reload  # 重启nginx服务
上一篇下一篇

猜你喜欢

热点阅读