Linux下安装Nginx

来源:互联网 发布:mac 双系统 win10 编辑:程序博客网 时间:2024/06/11 15:39
Nginx在Linux环境下可以通过编译源码的方式安装,最简单的安装命令如下:
wget http://nginx.org/download/nginx-1.2.0.tar.gz
tar zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure
make
sudo make install

按照以上命令,Nginx将被默认安装到/usr/local/nginx目录下。
查看nginx版本
/usr/local/nginx/sbin/nginx -v

启动Nginx
sudo /usr/local/nginx/sbin/nginx 

关闭Nginx
ps -ef | grep nginx
kill -9 pid

重新加载
/usr/local/nginx/sbin/nginx -s  reload 

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;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           root   /usr/local/song_zhuye;
           index  index.html index.htm;
   # proxy_pass http://120.24.84.77:8080;
        }

#Nginx反向代理到Tomcat服务器
location ^~ /rap/ {
            proxy_pass   http://120.24.84.77:8080/hudson/;
            proxy_redirect  off;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#对jsp和do结尾的url也去访问tomcat服务
#location ~ \.(jsp|do)$ {  
#proxy_pass http://127.0.0.1;
#proxy_redirect  off;
                #proxy_set_header  X-Real-IP $remote_addr;
                #proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        #}

location /biaobai{
#index  index.html index.htm login.html;
#alias  E:\songbai_workspace\forex_admin_web\admin;
alias /usr/local/tomcat/webapps/biaobai;
proxy_redirect   off;
proxy_set_header  Host $host;
proxy_set_header  X-Real-IP $remote_addr;
proxy_set_header  x-forwarded-for $proxy_add_x_forwarded_for;
}


        #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          8081;  
    server_name     localhost;  
    #access_log emb.info/logs/access.log;  
    location / {  
        #index index.html;  
           #root  emb.info/htdocs;  
        proxy_pass http://127.0.0.1:8080;
    } 
    }

    server {
listen 8082;
server_name www.songfayuan.date;
location / {
proxy_pass http://127.0.0.1:8080/hudson/;
}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}



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

    #config redmine
    #passenger_root /opt/redmine-3.3.3-0/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6;
    #passenger_ruby /usr/local/ruby/bin/ruby;
    
    #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;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /var/www/html;
            index  index.html index.htm;
        }

#zhai min ye mian config----
location /zhaimin {
            alias   /home/zhaimin;
            index  index.html index.htm;

    proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $remote_addr;
            proxy_connect_timeout 1;
            proxy_send_timeout 60; 
            proxy_read_timeout 60;
        }


#Apache config----
location ^~ /songfayuan/ {
            proxy_pass   http://127.0.0.1:7001/;
            proxy_redirect  off;
    proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#admin config----
location ^~ /youyu-admin/ {
            proxy_pass   http://127.0.0.1:8080;
            proxy_redirect  off;
    proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }


#redmine config----
location ^~ /redmine/ {
            proxy_pass   http://127.0.0.1:7002/redmine/;
            proxy_redirect  off;
    proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#hudson config----
location ^~ /hudson/ {
            proxy_pass   http://127.0.0.1:7080/hudson/;
            proxy_redirect  off;
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#pkg config----
        location ^~ /pkg-management/ {
            proxy_pass   http://127.0.0.1:7082;
            proxy_redirect  off;
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#zentao config----
        location ^~ /zentao/ {
            proxy_pass   http://127.0.0.1:1001;
            proxy_redirect  off;
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

#gogs config----
location ^~ /gogs/ {
            proxy_pass   http://127.0.0.1:3000;
            proxy_redirect  off;
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        }

location /git/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_redirect   off;
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  x-forwarded-for $proxy_add_x_forwarded_for;
}


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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}