Nginx编译安装和配置

环境准备:先安装准备环境

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

解压安装包:

编译nginx:

./configure  --prefix=/usr/local/nginx 
--sbin-path=/usr/local/nginx/sbin/nginx
--conf-path=/usr/local/nginx/conf/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--user=nginx --group=nginx
--with-http_ssl_module
--with-http_stub_status_module
--with-http_gzip_static_module
--http-client-body-temp-path=/var/tmp/nginx/client/
--http-proxy-temp-path=/var/tmp/nginx/proxy/
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
--with-pcre

生成脚本及配置文件:make

安装:make install

通过命令启动和关闭nginx

启动  /usr/local/nginx/sbin/nginx
如果报错,在网上找相应的解决方法
/usr/local/nginx/sbin/nginx/nginx  #启动 服务
/usr/local/nginx/sbin/nginx/nginx   -s  reload  #不停止服务重读配置文件
/usr/local/nginx/sbin/nginx/nginx -s stop #停止服务  #停止服务

nginx 主配置文件:nginx.conf

server {
  listen 80;
  server_name localhost;
  #charset koi8-r;
  #access_log logs/host.access.log main;
  location / {
    #root /var/www/html;
    index index.php index.html index.htm;
  }
  location ~ \.php$ {
    root /var/www/html;
    # 设置监听端口
    fastcgi_pass 127.0.0.1:9000;
    # 设置脚本文件请求的路径
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    # 引入fastcgi的配置文件
    include fastcgi_params;
    }
    #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;
  #}
}

 

重启nginx,

在根目录的文件中创建一个PHP文件,在浏览器中用ip就能访问了





posted @ 2018-03-08 15:40  会飞的小虫子  阅读(237)  评论(0编辑  收藏  举报