一、軟件安裝
1、環境說明
操作系統:CentOS 7.4 64位
nginx版本:1.16.1
安裝日期:2019/10/01
安裝用戶:root
2、安裝運行庫
yum -y install gcc gcc-c++ automake autoconf libtool make
3、安裝openssl(不用安裝,解壓即可)
$ cd /usr/local/src $ wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz $ tar -zxvf openssl-1.0.1t.tar.gz
4、安裝pcre
$ cd /usr/local/src $ wget https://ftp.pcre.org/pub/pcre/pcre-8.38.tar.gz $ tar -zxvf pcre-8.38.tar.gz $ cd pcre-8.38 $ ./configure $ make $ make install
5、安裝zlib
$ cd /usr/local/src $ wget http://zlib.net/zlib-1.2.11.tar.gz $ tar -zxvf zlib-1.2.11.tar.gz $ cd zlib-1.2.11 $ ./configure $ make $ make install
6、安裝nginx
$ cd /usr/local/src $ wget http://nginx.org/download/nginx-1.16.1.tar.gz $ tar -zxvf nginx-1.16.1.tar.gz $ cd nginx-1.16.1 $ ./configure --with-http_ssl_module \ --with-pcre=/usr/local/src/pcre-8.38 \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-openssl=/usr/local/src/openssl-1.0.1t $ make $ make install
二、軟件使用命令
nginx默認安裝路徑為 /usr/local/nginx
啟動:./sbin/nginx
關閉:/usr/local/nginx/sbin/nginx -s stop
重啟:/usr/local/nginx/sbin/nginx -s reopen
重新加載配置文件:/usr/local/nginx/sbin/nginx -s reload
三、軟件配置方法
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; proxy_cache_path D:/nginx-1.16.1/cache levels=1:1:1 keys_zone=pcache:10m max_size=2g; #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 65; #gzip on; server { listen 55556; server_name 127.0.0.1; proxy_cache pcache; #調用緩存 proxy_cache_key $request_uri; #把什么當鍵 proxy_cache_methods GET HEAD; #緩存哪些項 proxy_cache_valid 200 302 10m; #指定200 302響應碼的內容緩存10分鍾 proxy_cache_valid 404 1m; #指定404響應碼的內容緩存1分鍾 proxy_cache_use_stale http_502; #允許502響應碼的內容使用過期緩存 proxy_set_header X-Real-IP $remote_addr; #將實際的客戶端IP發送至后端服務器 add_header X-Via $server_addr; #將代理服務器的IP發至后端服務器 #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://127.0.0.1:55555/; root html; index index.html index.htm; } location /nationInterface/ { proxy_pass http://124.163.214.106:18064/nationInterface/; root html; index index.html index.htm; proxy_set_header X-Real-IP $remote_addr; #將實際的客戶端IP發送至后端服務器 add_header X-Via $server_addr; #將代理服務器的IP發至后端服務器 } location /CMAQ { autoindex on; root D:/dataCenter; add_header Cache-Control no-cache; add_header Pragma no-cache; add_header Expires 0; } #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 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # 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; # } #} }

注意事項:配置靜態目錄的時候,采用的是目錄拼接的方式,比如上圖的靜態目錄是:D:/dataCenter/CMAQ/。
如果linux下遇到權限問題,比如 13: Permission denied。從以下幾個方面排查:
1、root安裝的,那么啟動也要用root用戶
2、nginx.conf配置文件第一行,#user nobody要改成user root
3、是否缺少index.html
4、修改目錄權限:chmod -R 777 /data
5、要將SELinux設置為關閉。
開機啟動:
vi /etc/rc.local
添加
/usr/local/nginx/sbin/nginx
nginx,配置文件目錄瀏覽
location /gfs {
autoindex on;
root //public/share;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8;
}
