您好,登錄后才能下訂單哦!
這篇文章主要講解了“分布式服務Nginx搭建以及部署配置方法”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“分布式服務Nginx搭建以及部署配置方法”吧!
一. Nginx的部署及配置;
1.檢測系統的版本: centOS7
CentOS 7,使用yum安裝Nginx
安裝Nginx源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安裝該rpm后,我們就能在/etc/yum.repos.d/ 目錄中看到一個名為nginx.repo 的文件。
安裝完Nginx源后,就可以正式安裝Nginx了。
yum install -y nginx
以下是Nginx的默認路徑:
(1) Nginx配置路徑:/etc/nginx/
(2) PID目錄:/var/run/nginx.pid
(3) 錯誤日志:/var/log/nginx/error.log
(4) 訪問日志:/var/log/nginx/access.log
(5) 默認站點目錄:/usr/share/nginx/html
事實上,只需知道Nginx配置路徑,其他路徑均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查詢到
(1) 啟動:
nginx
(2) 測試Nginx配置是否正確:
nginx -t
(3) 優雅重啟:
nginx -s reload
(4) 查看nginx的進程號:
ps -ef |grep nginx
(5)nginx服務停止
nginx -s stop
kill -9 pid
編輯的nginx.conf配置文件如下
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 $request_time $upstream_response_time';
log_format log_wisecloud '{"project": "新云",'
'"@timestamp": "$time_local",'
'"remote_addr": "$remote_addr",'
'"request_host":"$http_host",'
'"request_api":"$uri",'
'"request_uri":"$request_uri",'
'"request_method": "$request_method",'
'"status": "$status",'
'"body_bytes_sent": "$body_bytes_sent",'
'"request_time": "$request_time",'
'"upstream_response_time": "$upstream_response_time",'
'"upstream_addr":"$upstream_addr",'
'"http_x_forwarded_for": "$http_x_forwarded_for",'
'"http_referrer": "$http_referer",'
'"http_user_agent": "$http_user_agent"}';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
client_max_body_size 2048m;
client_body_buffer_size 1024m;
client_header_timeout 4800s;
client_body_timeout 4800s;
client_header_buffer_size 1280m;
large_client_header_buffers 4 1280m;
fastcgi_connect_timeout 3000s;
fastcgi_send_timeout 3000s;
fastcgi_read_timeout 3000s;
fastcgi_buffer_size 1280k;
fastcgi_buffers 2 2560k;
fastcgi_busy_buffers_size 2560k;
fastcgi_temp_file_write_size 2560k;
fastcgi_ignore_client_abort on;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
proxy_ignore_client_abort on;
gzip on;
gzip_http_version 1.0;
gzip_min_length 1k;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/json application/x-www-form-urlencoded;
include /etc/nginx/conf.d/*.conf;
}
###################### 模塊配置 ####################
test-80.conf
server {
listen 80;
server_name xxxx.yyy.com;
access_log /var/log/nginx/cloud-cn.log log_cloud;
ssl_certificate /etc/nginx/ssl/cloud-cn.coud.com.pem;
ssl_certificate_key /etc/nginx/ssl/cloud-cn.cloud.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
#location @router {
# rewrite ^.*$ /index.html last;
#}
location /api/ {
proxy_pass http://192.168.1.13:8083/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
location /config/ {
proxy_pass http://localhost:8082/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /check.html {
alias /etc/nginx/health/check.html;
}
location / {
alias /home/html/dist/;
try_files $uri $uri/ /index.html;
index index.htm index.html index.php;
}
}
############### https 443 模塊配置###################
server {
listen 80;
server_name xxx.yyy.com;
access_log /var/log/nginx/name-cn.log log_name;
ssl_certificate /etc/nginx/ssl/test-cn.testeasy.com.pem;
ssl_certificate_key /etc/nginx/ssl/test.test.com.key;
server {
listen 80;
server_name xxx.yyy.com;
access_log /var/log/nginx/test-cn.log log_wisecloud;
ssl_certificate /etc/nginx/ssl/test-cn.test.com.pem;
ssl_certificate_key /etc/nginx/ssl/test.test.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
#location @router {
# rewrite ^.*$ /index.html last;
#}
location /api/ {
proxy_pass http://192.168.1.13:8083/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
location /config/ {
proxy_pass http://localhost:8082/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /check.html {
alias /etc/nginx/health/check.html;
}
location / {
alias /home/html/dist/;
try_files $uri $uri/ /index.html;
index index.htm index.html index.php;
}
}
感謝各位的閱讀,以上就是“分布式服務Nginx搭建以及部署配置方法”的內容了,經過本文的學習后,相信大家對分布式服務Nginx搭建以及部署配置方法這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。