linux nginx 完整安装配置笔记

岁酱吖の 提交于 2020-02-21 12:42:59

准备工作:阿里云 centos 7.6 X86_64、nginx 1.16.0.tar.gz

1、下载nginx

nginx官网:http://nginx.org/en/download.html

2、安装   

a、将压缩包解压到任意(不要含有中文及特殊字符)目录(目录自定)下,这个压缩包默认解压为nginx-1.16.0

b、进入解压目录进行安装,依次执行以下命令

     ./configure、make、make install

     若无错误提示,则表示安装成功!若出错一般为linux内核版本过低,没有提供相应的组件包(gcc、pcre、pcre-devel、zlib),到以下网站进行下载安装即可,https://sourceforge.net/projects

3、配置:包含多站点或多域名

切换至/usr/local/nginx/conf目录下,执行vi nginx.conf 命令,按以下内容配置,如下:

#user  root;
worker_processes  auto;

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


    server {
        listen       80;
        server_name  www.bjzkyc.com.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root html;
            proxy_pass   http://127.0.0.1:8080/webnew/;
            index  index.html index.htm;
          
            client_max_body_size 10m;
            client_body_buffer_size 128k;
            
             proxy_connect_timeout 3;
             proxy_send_timeout 30;
             proxy_read_timeout 30;

             proxy_buffer_size 4k;
             proxy_buffers 4 32k;
             proxy_busy_buffers_size 64k;
             proxy_temp_file_write_size 64k;
        }

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

    server{
        listen    80;
        server_name file.xxxx.com.cn;
        #tomcat 站点
        location / {
             proxy_pass http://127.0.0.1:8080/files/;
             index index.html index.htm index.jsp;
        }
       # error_page   500 502 503 504  /50x.html;
       # location = /50x.html {
      #      root   html;
     #   }

    }

......

保存后,切换至/usr/local/nginx/sbin目录下,启动或重启nginx(执行start nginx 或 nginx -s reload)

4、通过域名访问,显示相应的内容,即表示安装配置成功

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!