首先,你需要在安装好nginx。这是所有事情的前提。
接下来就可以配置nginx了:
首先找到nginx的文件,位置也就是在nginx目录下的/config/nginx.conf 。主要是对它进行修改。
接着:执行vi nginx.conf命令进入到nginx中.配置如下:
#user nobody;
user seedeer seedeer;
worker_processes 4;
#error_log logs/error.log error;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 10240;
}
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 600s;
server_tokens off;
#gzip压缩功能设置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
# http_proxy 设置
client_max_body_size 50m;
client_body_buffer_size 128k;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
proxy_buffer_size 128k;
proxy_buffers 32 128k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/seedeer/programs/nginx/proxy_temp 1 2;
#cache
#proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache_one:200m inactive=5d max_size=400m;
#proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
#设定负载均衡后台服务器列表
upstream sdssoBackend {
server 192.168.2.67:9082 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.2.68:9082 weight=1 max_fails=2 fail_timeout=30s;
sticky name=com.seedeer.sdsso.UAT.route domain=test-reg.seedeer.com;
check interval=5000 rise=2 fall=3 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
upstream SM {
server 192.168.2.142:8181 weight=1 max_fails=2 fail_timeout=30s;
}
upstream OW {
server 192.168.2.60:8085 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 88;
server_name www.abc.com;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
if ($request_uri ~ '^/') {
proxy_pass http://SM;
}
if ($request_uri ~ '^/OW.*') {
proxy_pass http://OW;
}
root html;
index index.html index.htm;
}
#location ~ .*\.(gif|jpg|png|html|htm|css|js|flv|ico|swf)(.*) {
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_cache cache_one;
# proxy_cache_valid 200 302 1h;
# proxy_cache_valid 301 1d;
# proxy_cache_valid any 1m;
# expires 30d;
#}
location /status {
check_status;
access_log off;
#allow 192.168.17.113;
#allow 192.168.62.91;
#deny all;
allow all;
}
location /demo {
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 99;
server_name test-datacaciques.seedeer.com;
location /datacaciques {
root html;
index datacaciques.html;
}
}
# 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服务,由于配置好了nginx,所以需要先关闭。执行nginx需要进入到sbin中(sbin是和nginx.conf父文件夹同一个级别的)。
执行关闭nginx命令:./nginx -s stop。
这样nginx就会停止,可以用ps -ef | grep nginx查看服务是否停止。
接着执行启动nginx命令:./nginx
这样nginx就重新启动了,可以用ps -ef | grep nginx查看服务重启了。