• nginx配置文件分开配置


    在Linux中不同的用户都可能用到Nginx,如果不同的用户无法达成一个对nginx.conf编写标准,势必会导致nginx.conf里的内容变的相当混乱,极难维护。所以这里建议新建一个文件夹,这个文件夹中分放不同用户所需要反向代理的配置文件。

    nginx.conf 文件尽量不做修改,只需在最末尾加上  include conf.d/*.conf;

    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;
        
        # upload file max size
        client_max_body_size 300m;
    
        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   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;
        #    }
        #}
        
        
        # 各个域名单独控制
        include conf.d/*.conf;
        
    }
    复制代码

    在conf.d文件中放入不同用户的conf文件。

    如: zhangsan.conf   lisi.conf

    zhangsan.conf

    复制代码
    server {
        listen 80;
        server_name    zhangsan.xxx.com;
        location / {
            proxy_set_header    Host            $host:80;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_hide_header   X-Powered-By;
            proxy_pass http://127.0.0.1:8080;    
        }
    }
    复制代码

     laravel 配置:

    server
    {
        listen 80;
        server_name www.asia.com;
        index index.php index.html index.htm default.php default.htm default.html;
        root /www/web/laravelOne/public;
       
        add_header Cache-Control no-store;    
    
        location / {
            try_files $uri $uri/
            /index.php$is_args$query_string;
        }
        location ~ .php$ {
            try_files $uri =404;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME
            $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
    
    
    }

    thinkphp:

    server
    {
        listen 80;
        server_name jmw.osd-asia.com;
        index index.php index.html index.htm default.php default.htm default.html;
        root /www/web/zzcms2019;
    
        location / {
            if ( -f $request_filename) {
                break;    
            }
    
            if ( !-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
                break;    
            }
        }    
    
        location ~ .php {
            set $script $uri;
            set $path_info "";
            if ($uri ~ "^(.+.php)(/.+)") {
                set $script $1;
                set $path_info $2;    
            }    
    
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param PATH_INFO $path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$script;
            fastcgi_param SCRIPT_NAME $script;
            try_files $uri =404;
        }
    
    }
  • 相关阅读:
    [BOST] 博赞有机的学习技巧
    [BOST] 你的大脑比你想象的更优秀
    Markdown学习笔记
    nodejs原生态模块,写个聊天室
    【2】自定义WindowsForm分页控件使用【共两篇】
    【1】自定义WindowsForm分页控件使用【共两篇】
    《Log4net写出适合自己的日志类》第三篇【终】【怎样让它适合你自己需求】
    《Log4net写出适合自己的日志类》第二篇【没有理论的实践是盲目】
    《Log4net写出适合自己的日志类》第一篇【上来就是干,先实践后理论】
    记忆留住深刻过往,博客写出平淡事迹【博客首篇】
  • 原文地址:https://www.cnblogs.com/jasonLiu2018/p/11758892.html
Copyright © 2020-2023  润新知