nginx运行状态查看

查看80端口占用情况:
netstat -tunlp | grep 80

# 查看进程是否运行
ps -A | grep nginx

# 强制关闭nginx
pkill nginx

 

【开始安装】(引自网络教程)

https://www.runoob.com/linux/nginx-install-setup.html

将教程内下载地址替换为:https://nginx.org/download/nginx-1.22.0.tar.gz

 

【快速安装指令-无脑复制粘贴即可,安装后nginx在这里:/usr/local/nginx】

1、环境安装:

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

 

2、pcre安装 (目录位置/usr/local/pcre-8.35)

cd /usr/local && wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz && tar zxvf pcre-8.35.tar.gz && cd pcre-8.35 && ./configure && make && make install && cd .. && rm -rf pcre-8.35.tar.gz && pcre-config --version

 

3、nginx安装 (目录位置/usr/local/nginx)

cd /usr/local && wget https://nginx.org/download/nginx-1.22.0.tar.gz && tar zxvf nginx-1.22.0.tar.gz && cd nginx-1.22.0 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35 && make && make install && cd .. && rm -rf nginx-1.22.0.tar.gz && rm -rf nginx-1.22.0 && /usr/local/nginx/sbin/nginx -v

 

4、配置使用用户

/usr/sbin/groupadd www && /usr/sbin/useradd -g www www

 

5、配置nginx.conf(存放位置: /usr/local/nginx/conf)

配置文件备份后新建配置文件:

cd /usr/local/nginx/conf/ && mv nginx.conf nginx.conf-bak && vim nginx.conf

 

下方可粘贴用基础配置文件(注意在VIM里先按i进入编辑状态再粘贴):

user www www; #运行用户
worker_processes 1; #设置值和CPU核心数一致
error_log /usr/local/nginx/logs/nginx_error.log crit; #错误日志位置和日志级别
pid /usr/local/nginx/nginx.pid; #目录和安装位置一致才行,按教程安装的不用改目录
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
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';
  
#charset gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;


  #limit_zone crawler $binary_remote_addr 10m;

 #下面是server虚拟主机的配置
 server
  {
    listen 80;#监听端口
    server_name localhost;#域名
    index index.html index.htm index.php; #配置增加支持php文件解析
    root /usr/local/nginx/html;#站点目录,目录要存在
      location ~ .*.(php|php5)?$
    {
      #fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_pass 127.0.0.1:9000; #遇到php这类动态解析文件丢给9000端口的程序处理
      fastcgi_index index.php; #配置增加支持php文件解析
      include fastcgi.conf;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
  # access_log off;
    }
    location ~ .*.(js|css)?$
    {
      expires 15d;
   # access_log off;
    }
    access_log off;
  }

}

 

6、配置检查

cd /usr/local/nginx/sbin && ./nginx -t

 

7、启动nginx

cd /usr/local/nginx/sbin && ./nginx

 

延伸教程:

https://www.cnblogs.com/brad93/p/16647499.html

https://www.cnblogs.com/brad93/p/16649524.html

 

开机启动设置:https://www.cnblogs.com/piscesLoveCc/p/5867900.html

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/brad93/p/16620709.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程

4249 0元 限免
3032 9.8元 98元 1折