Nginx

 yum install -y nginx
vi /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    use epoll;
    worker_connections 10240;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
#    tcp_nopush          on;
#    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    include /etc/nginx/conf.d/*.conf;
}

vi /etc/nginx/conf.d/default.conf

upstream app {
    least_conn;
    server x.x.x.x:80;
    server x.x.x.x:80;
    server x.x.x.x:80;
    server x.x.x.x:80;
}

upstream app-php7 {
    server x.x.x.x:80;
}

server {
    listen 80;
    server_name xxx.com;

    location / {
        proxy_pass http://app-php7;
        proxy_set_header    Host             $host;
        proxy_set_header    X-Real-IP        $remote_addr;
        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
        proxy_redirect      default;
    }
}


server {
    listen 80 default_server;
    server_name _;

    location / {
        proxy_pass http://app;
        proxy_set_header    Host             $host;
        proxy_set_header    X-Real-IP        $remote_addr;
        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
        proxy_redirect      default;
    }
}

systemctl restart nginx
systemctl enable nginx

你可能感兴趣的:(nginx)