centos7.3+nginx1.8+php7.1+mysql5.7 安装(一安装nginx)

来源:互联网 发布:软件搬家到sd卡的软件 编辑:程序博客网 时间:2024/05/22 07:05

1、先卸载老版本

[plain] view plain copy
  1. yum remove nginx  


2、编辑nginx的yum源配置

[plain] view plain copy
  1. vi /etc/yum.repos.d/nginx.repo  

往里面写入

[plain] view plain copy
  1. [nginx]  
  2. name=nginx repo  
  3. baseurl=http://nginx.org/packages/centos/7/x86_64/  
  4. gpgcheck=0  
  5. enabled=1  

3、安装

[plain] view plain copy
  1. yum install nginx  


启动

service nginx start
systemctl enable nginx


查看nginx 版本 nginx -v

查看进程 ps aux|grep nginx

说明:如果想要安装其他版本的只要修改 nginx的yum源配置重安装即可

具体版本支持请参考官方文档

http://nginx.org/en/linux_packages.html#stable

二、配置nginx

配置nginx解析PHP

    vi  /etc/nginx/nginx.conf;

    

user  nginx;
worker_processes  2;


error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;




events {
    worker_connections  1024;
}




http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    keepalive_timeout  300;


    #gzip  on;


    proxy_read_timeout 3s;


    proxy_buffer_size   256k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;


    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;
    client_max_body_size 256m;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256m;
    fastcgi_temp_file_write_size 256m;


    include /etc/nginx/conf.d/*.conf;
}




cd  /etc/nginx/conf.d 

ls

vi default.conf

server {


      listen  80;
      server_name www.xxx.com;
      set  $root_path  /www/apps/project/public;
      root $root_path;


      index index.php index.html index.htm;


      try_files $uri $uri/ @rewrite;


      location @rewrite {
          rewrite ^/(.*)$ /index.php?_url=/$1;
      }


      location ~ \.php {


          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index /index.php;


          fastcgi_split_path_info       ^(.+\.php)(/.+)$;
          fastcgi_param PATH_INFO       $fastcgi_path_info;
          fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include                       fastcgi_params;
      }


#      location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
#          root $root_path;
#      }


      location ~ /\.ht {
          deny all;
      }
}


三。虚拟主机

vi   /etc/hosts 






阅读全文
1 0
原创粉丝点击