Nginx 簡易安裝配置1

安裝環境:centOS 7.4

nginx: version -1.13.10

文件目錄:默認

默認:prce 8.25 (使Nginx 支持 Rewrite 功能)(如無自行安裝)(本文安裝位置在/opt文件夾下)

[plain] view plain copy
  1. wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz  

以防萬一:安裝編譯庫

[plain] view plain copy
  1. yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel  

1、安裝

①獲取nginx (可自行百度官網下載)

[plain] view plain copy
  1. wget http://nginx.org/download/nginx-1.13.10.tar.gz
 ②解壓
[plain] view plain copy
  1. tar -zxvf nginx-1.13.10.tar.gz  
 ③進入並編譯安裝
[plain] view plain copy
  1. ./configure 
[plain] view plain copy
  1. make && make install  
 ④查看nginx版本
[plain] view plain copy
  1. /usr/local/nginx/sbin/nginx -v  

2、配置

     ①創建 Nginx 運行使用的用戶 nginx:
[plain] view plain copy
  1. /usr/sbin/groupadd nginx  
  2. /usr/sbin/useradd -g nginx nginx    
配置nginx.conf ,將/usr/local/nginx/conf/nginx.conf替換爲以下內容

[plain] view plain copy
  1. user nginx nginx;  
  2. worker_processes  1; # 設置值和CPU核心數一致  
  3. error_log /opt/nginx/logs/nginx_error.log crit; #日誌位置和日誌級別  
  4. #error_log  logs/error.log;  
  5. #error_log  logs/error.log  notice;  
  6. #error_log  logs/error.log  info;  
  7.   
  8. #pid        logs/nginx.pid;  
  9. pid /opt/nginx/nginx.pid;  
  10. #Specifies the value for maximum file descriptors that can be opened by this process.  
  11. worker_rlimit_nofile 65535;  
  12. events {  
  13.     use epoll;  
  14.     worker_connections  65535;  
  15. }  
  16.   
  17.   
  18. http {  
  19.     include       mime.types;  
  20.     default_type  application/octet-stream;  
  21.       log_format main  '$remote_addr - $remote_user [$time_local] "$request" '  
  22.                '$status $body_bytes_sent "$http_referer" '  
  23.                '"$http_user_agent" $http_x_forwarded_for';  
  24.   
  25. #chartset gb2312  
  26.   server_names_hash_bucket_size 128;  
  27.   client_header_buffer_size 32k;  
  28.   large_client_header_buffers 4 32k;  
  29.   client_max_body_size 8m;  
  30.        
  31.   sendfile on;  
  32.   tcp_nopush on;  
  33.   keepalive_timeout 60;  
  34.   tcp_nodelay on;  
  35.   fastcgi_connect_timeout 300;  
  36.   fastcgi_send_timeout 300;  
  37.   fastcgi_read_timeout 300;  
  38.   fastcgi_buffer_size 64k;  
  39.   fastcgi_buffers 4 64k;  
  40.   fastcgi_busy_buffers_size 128k;  
  41.   fastcgi_temp_file_write_size 128k;  
  42.   gzip on; #對響應數據進行壓縮  
  43.   gzip_min_length 1k;  
  44.   gzip_buffers 4 16k;  
  45.   gzip_http_version 1.0;  
  46.   gzip_comp_level 2;  
  47.   gzip_types text/plain application/x-javascript text/css application/xml;  
  48.   gzip_vary on;  
  49.   
  50.   #limit_zone crawler $binary_remote_addr 10m;  
  51.   #下面是server虛擬主機的配置    
  52. server  
  53.   {  
  54.     listen 80; #監聽端口  
  55.     server_name localhost;#域名  
  56.     index index.html index.htm index.php;  
  57.     root /opt/nginx/html; #站點目錄  
  58.       location ~ .*\.(php|php5)?$  
  59.     {  
  60.     #fastcgi_pass unix:/tmp/php-cgi.sock;  
  61.        fastcgi_pass 127.0.0.1:9000;  
  62.        fastcgi_index index.php;  
  63.        include fastcgi.conf;  
  64.      }  
  65.       location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$  
  66.      {  
  67.       expires 30d;  
  68.     # access_log off;  
  69.     }  
  70.     location ~ .*\.(js|css)?$  
  71.     {  
  72.       expires 15d;  
  73.  # access_log off;  
  74.      }  
  75.       access_log off;    
  76.    }  
  77.    
  78.   }  

③檢查配置文件ngnix.conf的正確性命令

[plain] view plain copy
  1. /usr/local/nginx/sbin/nginx -t  

Nginx 啓動命令如下:

[plain] view plain copy
  1. /usr/local/nginx/sbin/nginx  

 ⑤從瀏覽器訪問我們配置的站點ip:



⑥其他常用命令:

[plain] view plain copy
  1. /usr/local/nginx/sbin/nginx -s reload            # 重新載入配置文件  
  2. /usr/local/nginx/sbin/nginx -s reopen            # 重啓 Nginx  
  3. /usr/local/nginx/sbin/nginx -s stop              # 停止 Nginx  
  4. /usr/local/nginx/sbin/nginx -s quit – 優雅關閉 (等待 worker 線程完成處理  
  5.  nginx -t #測試配置    
  6.  nginx -q #測試配置時,只輸出錯誤信息    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章