只簡單說一下upstream的配置,如何進行負載均衡後續還須要多瞭解php
爲了避免污染原有的nginx.conf,提早複製一份配置文件作試驗,而後啓動nginx時加載nginx_test.confhtml
啓動命令:nginx
[root@localhost conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx_test.conf
-c參數表示加載指定的配置文件,後面跟的是文件路徑
upstream tomcat { server localhost:8080; # 對應server下location中添加的 proxy_pass } upstream ApprPhD { server 192.168.0.1XX:3030; }
server { listen 80; server_name hanmk.com; location / { root /tmp/data/; autoindex on; } } server { listen 80 default_server; server_name demo.com ; #charset koi8-r; #access_log logs/host.access.log main; # location / { # root html; # index index.html index.htm; # } location / { proxy_pass http://tomcat; # 對應upstream爲tomcat,訪問本地tomcat } #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; #} location /jenkins { proxy_pass http://tomcat; #對應upstream爲tomcat,訪問本地tomcat中部署的jenkins proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; #獲取真實ip proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#獲取代理者的真實ip proxy_redirect off; } location /ApprPhD { proxy_pass http://ApprPhD; # 對應upstream爲ApprPhD,訪問1XX服務器部署的ApprPhd proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; #獲取真實ip proxy_set_header REMOTE-HOST $remote_addr; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#獲取代理者的真實ip proxy_redirect off; } }