Nginx 安装配置【必须把文件到放到机器上】

【必须把所有下载的gz文件到放到机器上;编译】

1.安装nginx之前的编译软件

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

make 命令安装

zlib 和 zlib-devel 解压命令安装:

red hat:wget https://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz/download -o zlib-1.2.8.tar.gz
ubuntu:apt install zlib1g

gcc 的安装
g++ 的安装

libtool 通用库工具的安装
ubuntu:sudo apt install libtool
Ubuntu:sudo apt-get install zlib1g-dev
Ubuntu:sudo apt-get install g++

openssl 一个安全套接字层密码库


二、首先要安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

1、下载 PCRE 安装包,下载地址:wget http://downloads.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz

daokr#wget http://downloads.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz

2、解压安装包:

[root@dksrc]# tar zxvf pcre-8.33.tar.gz

3、进入安装包目录

[root@dksrc]# cd pcre-8.33

4、编译安装 

[root@dkpcre-8.35]# ./configure --prefix=/usr/local/src/pcre-8.33
[root@dkpcre-8.35]# make && make install

    查找pcre 的默认安装路径 

root@VM-0-4-ubuntu:/# find -name pcre
./home/ubuntu/downfile/nginx-1.5.8/auto/lib/pcre

如果报错看下面链接:

ubuntu编译PCRE时出现 line 81: aclocal-1.14: command not found错误

 

5、查看pcre版本

[root@dkpcre-8.35]# pcre-config --version

 

安装openssl

1.下载地址 

root:wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz

2.编辑配置安装路径

root:./config --prefix=/usr/local/src/openss-1.0

3.输入make && make install 安装

make && make install

4.查看版本

daokr#openssl version -a

安装 Nginx

1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.5.8.tar.gz

[root@dk src]#wget http://nginx.org/download/nginx-1.5.8.tar.gz

2、解压安装包

[root@dksrc]# tar zxvf nginx-1.5.8.tar.gz

3、进入安装包目录

[root@dksrc]# cd nginx-1.5.8

4、编译安装

[root@dknginx-1.6.2]# ./configure --prefix=/home/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/home/daokr/downfile/openssl-1.0.2h --with-pcre=/home/daokr/downfile/pcre-8.33
[root@dknginx-1.6.2]# make
[root@dknginx-1.6.2]# make install

在编译的时候如果没有出现 creating objs/Makefile 这行;说明哪里错了;要按错误来修改
这里有个坑;就是

--with-openssl--with-pcre 的路径 是压缩包解压后源文件;千万别搞错了路径


5、查看nginx版本

[root@dknginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

到此,nginx安装完成。

Nginx 配置

创建 Nginx 运行使用的用户 www:

添加用户组www

添加用户并赋予www的权限组

[root@dk conf]# groupadd www 
[root@dk conf]# useradd -g www www

配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容

默认配置:

 启动地址:/usr/sbin/nginx 下面关闭

root@DK:/usr/sbin# ./nginx
root@DK:/usr/sbin# ps -ef|grep nginx
root     25113     1  0 10:15 ?        00:00:00 nginx: master process ./nginx
www      25114 25113  0 10:15 ?        00:00:00 nginx: worker process
root     25118 25074  0 10:15 pts/22   00:00:00 grep --color=auto nginx

测试配置是否正确命令:

root@DK:/etc/nginx# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动和停用:

Nginx 其他命令
以下包含了 Nginx 常用的几个命令:
/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx

 安装完成后简单的修改下配置文件:

user  www www;
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       1180;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        set $root_path "/home/daokr/web";
                        
        root $root_path;
        index index.php index.html index.htm;
        location / {
            root   html;
            index  index.html index.htm;
        }

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

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

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

下面是工作的实际的nginx配置:

#user oracle.dba;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
pid    /home/nginx/logs/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 10240;
}

http
{
    include    mime.types;
    default_type application/octet-stream;
    
    server_tokens off;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 4k;
    large_client_header_buffers 4 32k;
    client_max_body_size 64m;
    sendfile     on;
    tcp_nopush  on;
    tcp_nodelay    on;
    keepalive_timeout 60s;
    
    open_file_cache max=10240 inactive=20s;
    open_file_cache_valid 60s;
    open_file_cache_min_uses 1;

    fastcgi_connect_timeout 180s;
    fastcgi_send_timeout 180s;
    fastcgi_read_timeout 180s;
    
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    
    proxy_connect_timeout 180s;
    proxy_read_timeout 180s;
    proxy_send_timeout 180s;
    
    proxy_buffer_size 64k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    
    gzip on;
    gzip_min_length  1k;
    gzip_buffers 4 64k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types    text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    
    include server/*.txt;
    
    #access loger format
    log_format    access    '$remote_addr $http_x_forwarded_for $remote_user [$time_local] "$request" [$request_length/$bytes_sent] '
                         '$status "$http_referer" "$http_user_agent"';
    access_log logs/access.log access;
    log_not_found off;
    open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
    
    error_log /home/nginx/logs/error.log error;
    
     # limit_zone crawler; 
     # $binary_remote_addr  10m;
    
    #WebSocket Upgrade
    #map $http_upgrade $connection_upgrade 
    #{
    #    default upgrade;
    #    ''      close;
    #}
    
    #server 
    #{
    #    #WebSocket Proxy Port
    #    listen      12800;
    #    server_name localhost;
    #
    #    location / 
    #    {
    #        #PHP WebSocket port
    #        proxy_pass http://localhost:12801;
    #        proxy_set_header X-Real-IP $remote_addr;
    #        proxy_set_header Host $host;
    #        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #
    #        proxy_http_version 1.1;
    #        proxy_set_header Upgrade $http_upgrade;
    #        proxy_set_header Connection "upgrade";
    #    }
    #}


    server 
    {
        ##---xpass-1.0.0---##
        listen 20030;
        server_name localhost;
        charset    utf-8;
    
        ##ssl configure                                
        #ssl                  on;                                
        #ssl_certificate      cert/lianyinggufen_com.crt;
        #ssl_certificate_key  cert/lianyinggufen_com.key;                          
        #ssl_session_timeout  5m;                                
        #ssl_protocols        SSLv3 TLSv1;                               
        #ssl_ciphers          HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;       
        #ssl_prefer_server_ciphers   on;                                 
            
        ## phalcon-config
        set $root_path "/home/oracle/xpass-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$
    
        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|apk|ipa|plist)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }
    
        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }
    
        location ~ /.ht 
        {
            deny all;
        }
    }  
    
    server 
    {
        ##---xpay-1.0.0(http)---##
        listen 20031;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xpay-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
        
        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx|zip|uploads|xml|rar)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    } 
#
#    server 
#    {
#        ##---wxqyh---##
#        listen 20038;
#        server_name localhost;
#        charset    utf-8;
#
#        ## phalcon-config
#        set $root_path "/home/oracle/wxqyh-1.0.0/public";
#                
#        root $root_path;
#        index index.php index.html index.htm;
#        try_files $uri $uri/ @rewrite;
#        
#        #for document_root - ajax request
#        location /
#        {
#            rewrite ^(.*)$ /index.php?_url=$1;
#        }
#        
#        #for all others
#        location @rewrite 
#        {
#            rewrite ^/(.*)$ /index.php?_url=$1;
#        }
#        
#        location ~ .php 
#        {
#            # try_files $uri = 404;
#            fastcgi_index index.php;
#            
#            # fastcgi_pass 127.0.0.1:9000;
#            fastcgi_pass unix:/tmp/php-cgi.sock;
#            
#            include fastcgi_params;
#            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;
#        }
#        
#        # cache folder
#        # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
#        
#        # cache file type
#        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
#        {
#            root $root_path;
#            access_log  off;
#            expires     30d;            
#        }
#
#        location ~ .ico
#        {
#            root $root_path;
#            access_log  off;
#            expires     30d;            
#        }
#
#        location ~ /.ht 
#        {
#            deny all;
#        }
#    } 
#
    server 
    {
        ##---xmer-1.0.0---##
        listen 20033;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xmer-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xagent-1.0.0---##
        listen 20034;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xagent-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xserv-1.0.0---##
        listen 20035;
        server_name localhost;
        charset    utf-8;
        
        ## phalcon-config
        set $root_path "/home/oracle/xserv-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xfinance-1.0.0---##
        listen 20036;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xfinance-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xapp-1.0.0  SSL---##
        listen 20037;
        server_name localhost;
        charset    utf-8;
        
        ##ssl configure                                
        ssl                  on;                                
        ssl_certificate      ssl/boshang.crt;
        ssl_certificate_key  ssl/boshang.key;                          
        ssl_session_timeout  5m;                                
        ssl_protocols        SSLv3 TLSv1;                               
        ssl_ciphers          HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;       
        ssl_prefer_server_ciphers   on;
        
        ## phalcon-config
        set $root_path "/home/oracle/xapp-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx|exe|app|appfile)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xapp-1.0.0 not ssl---##
        listen 20042;
        server_name localhost;
        charset    utf-8;
        
        ## phalcon-config
        set $root_path "/home/oracle/xapp-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }

    server 
    {
        ##---XOPEN-1.0.0---##
        listen 20041;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xopen-1.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
        
        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---XOPEN-1.0.0---##
        listen 20046;
        server_name localhost;
        charset    utf-8;

        ## phalcon-config
        set $root_path "/home/oracle/xdemo";
                
        root $root_path;
        index index.php index.html index.htm;
        #try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            #rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            #rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
    
        
        # cache folder
        # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
        
        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx|html|htm|http)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }
        
        location ~ /.ht 
        {
            deny all;
        }
    }

    #server 
    #{
    #    ##---xweixin-1.0.0---##
    #    listen 20041;
    #    server_name localhost;
    #    charset    utf-8;
    #
    #    ## phalcon-config
    #    set $root_path "/home/oracle/xweixin-1.0.0/public";
    #            
    #    root $root_path;
    #    index index.php index.html index.htm;
    #    try_files $uri $uri/ @rewrite;
    #    
    #    #for document_root - ajax request
    #    location /
    #    {
    #        rewrite ^(.*)$ /index.php?_url=$1;
    #    }
    #    
    #    #for all others
    #    location @rewrite 
    #    {
    #        rewrite ^/(.*)$ /index.php?_url=$1;
    #    }
    #    
    #    location ~ .php 
    #    {
    #        # try_files $uri = 404;
    #        fastcgi_index index.php;
    #        
    #        # fastcgi_pass 127.0.0.1:9000;
    #        fastcgi_pass unix:/tmp/php-cgi.sock;
    #        
    #        include fastcgi_params;
    #        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;
    #    }
    #    
    #    # cache folder
    #    # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
    #    
    #    # cache file type
    #    location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
    #    {
    #        root $root_path;
    #        access_log  off;
    #        expires     30d;            
    #    }
    #
    #    location ~ .ico
    #    {
    #        root $root_path;
    #        access_log  off;
    #        expires     30d;            
    #    }
    #
    #    location ~ /.ht 
    #    {
    #        deny all;
    #    }
    #}
    #
    #server 
    #{
    #    ##---xca-1.0.0---##
    #    listen 20044;
    #    server_name localhost;
    #    charset    utf-8;
    #
    #    ## phalcon-config
    #    set $root_path "/home/oracle/xca-1.0.0/public";
    #            
    #    root $root_path;
    #    index index.php index.html index.htm;
    #    try_files $uri $uri/ @rewrite;
    #    
    #    #for document_root - ajax request
    #    location /
    #    {
    #        rewrite ^(.*)$ /index.php?_url=$1;
    #    }
    #    
    #    #for all others
    #    location @rewrite 
    #    {
    #        rewrite ^/(.*)$ /index.php?_url=$1;
    #    }
    #    
    #    location ~ .php 
    #    {
    #        # try_files $uri = 404;
    #        fastcgi_index index.php;
    #        
    #        # fastcgi_pass 127.0.0.1:9000;
    #        fastcgi_pass unix:/tmp/php-cgi.sock;
    #        
    #        include fastcgi_params;
    #        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;
    #    }
    #    
    #    # cache folder
    #    # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
    #    
    #    # cache file type
    #    location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
    #    {
    #        root $root_path;
    #        access_log  off;
    #        expires     30d;            
    #    }
    #
    #    location ~ .ico
    #    {
    #        root $root_path;
    #        access_log  off;
    #        expires     30d;            
    #    }
    #
    #    location ~ /.ht 
    #    {
    #        deny all;
    #    }
    #}
    
    server 
    {
        ##---xwebs---##
        listen 20044;
        server_name localhost;
        charset    utf-8;
    
        ## phalcon-config
        set $root_path "/home/oracle/xwebs/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(.+)/(js|css|img|images|flv|swf|fonts|download|product)/(.+)$
        
        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }
    
        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }
    
        location ~ /.ht 
        {
            deny all;
        }
    }
    
    server 
    {
        ##---xcar-1.0.0  SSL---##
        listen 20050;
        server_name localhost;
        charset    utf-8;
        
        ##ssl configure                                
        ssl                  on;                                
        ssl_certificate      ssl/xcar.cer;
        ssl_certificate_key  ssl/xcar.pem;                          
        ssl_session_timeout  5m;                                
        ssl_protocols        SSLv3 TLSv1;                               
        ssl_ciphers          HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;       
        ssl_prefer_server_ciphers   on;
        
        ## phalcon-config
        set $root_path "/home/oracle/xcars-1.0.0/public";
                
        root $root_path;
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewrite;
        
        #for document_root - ajax request
        location /
        {
            rewrite ^(.*)$ /index.php?_url=$1;
        }
        
        #for all others
        location @rewrite 
        {
            rewrite ^/(.*)$ /index.php?_url=$1;
        }
        
        location ~ .php 
        {
            # try_files $uri = 404;
            fastcgi_index index.php;
            
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            
            include fastcgi_params;
            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;
        }
        
        # cache folder
        # location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$

        # cache file type
        location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|download|xlsx|exe|app|appfile)$
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ .ico
        {
            root $root_path;
            access_log  off;
            expires     30d;            
        }

        location ~ /.ht 
        {
            deny all;
        }
    }
    
server {
  listen 5601;
  server_name localhost;
    charset utf8;
  location / {
          auth_basic "Restricted Access";
          auth_basic_user_file /home/nginx/conf/htpasswd.users; 
      proxy_pass http://10.8.21.124:5601$request_uri;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
}
    
}    

tcp
{        
    timeout 1d;  
    proxy_read_timeout 1d;  
    proxy_send_timeout 1d;  
    proxy_connect_timeout 14400;

    # ------ 192.168.2.11(oracle proxy) ------
    upstream oracle_11521 {
       server localhost:21521;
       check interval=3000 rise=4 fall=5 timeout=3000 type=tcp;
    }        
    server {
        listen 11521;
        proxy_pass oracle_11521;
        so_keepalive on;  
        tcp_nodelay on;
    }
}
 
原文地址:https://www.cnblogs.com/wanglijun/p/8693814.html