1.我這里是nginx-1.13.0-1.x86_64 .rpm(點擊下載)版本的。
2.安裝nginx的相應環境。有些環境可能不必須,但是安裝了,確保以防萬一,多多益善
yum install gd-devel
yum install gcc-c++
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-developenssl openssl-devel pcre pcre-devel
yum install libgd2-devel
yum install libpcre-devel
yum install libcurl-devel
yum install gd-devel
3.我再opt目錄下建立了一個software文件夾,用來存放資源包的
進入該目錄 cd /opt/software/
隨之解壓 rpm -ivh nginx-1.13.0-1.x86_64 .rpm
4.這個時候,nginx的相關配置都在你/etc/nginx目錄下
根據自己的需要,修改nginx.conf
user nobody; worker_processes auto; worker_rlimit_nofile 102400; pid /run/nginx.pid; events { use epoll; worker_connections 10240; multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; types_hash_max_size 2048; server_tokens off; # allow the server to close connection on non responding client, this will free up memory reset_timedout_connection on; # number of requests client can make over keep-alive -- for testing environment keepalive_requests 1000; proxy_next_upstream error timeout invalid_header; proxy_intercept_errors on; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_redirect http:// $scheme://; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ""; proxy_http_version 1.1; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE # ssl_prefer_server_ciphers on; ## # Logging Settings ## log_format main '$upstream_addr $scheme $http_host [$request_time|$upstream_response_time|$upstream_status] ' '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $gzip_ratio'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_static on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/javascript application/javascript application/x-javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype application/x-font-ttf application/vnd.ms-fontobject image/x-icon; gzip_disable "msie6"; ## # Virtual Host Configs ## include /etc/nginx/http-conf.d/*.conf; include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-available/*.conf; } stream { include /etc/nginx/stream-conf.d/*.conf; include /etc/nginx/stream-enabled/*; }
此時,你可以把你的IP端口號寫在這個配置里面,也可以寫在這個下面
/etc/nginx/sites-available/*.conf;
這里我把我的IP端口就寫在這里,命名叫做TestSite.conf
upstream upstream_10009 { #sticky; ip_hash; server 10.10.0.112:10009; server 10.10.0.113:10009; keepalive 64; } upstream upstream_10010 { sticky; server 10.10.0.112:10010; server 10.10.0.113:10010; keepalive 64; } upstream upstream_10020 { sticky; server 10.10.0.112:10020; server 10.10.0.113:10020; keepalive 64; } upstream upstream_10030 { sticky; server 10.10.0.112:10030; server 10.10.0.113:10030; keepalive 64; }
#------------------------------
#------------------------------
因為我的服務器項目需要傳遞Token,我使用的是 ip_hash 負載算法。
配置完畢之后,可以使用 可以用systemctl啟動、重載、停止nginx
例如:
systemctl status nginx.service #狀態
systemctl start nginx.service #開始
systemctl stop nginx.service #停止
然后開始訪問你的項目吧!此部署nginx是最省心的方法。