這次由于時間有限,所以我就沒有用編譯安裝來啟動LMP,只有Nginx 是編譯安裝的
因為是在centos7上面安裝的Nginx所以我們這里由于能力有限,暫時不能將其加入開機啟動,日后我會進行改進,將其加入開機啟動。這里我們給出Nginxd的編譯選項及環境
yum groupinstall "Development Tools" "Server Platform Deveopment"; yum install openssl-devel pcre-devel; groupadd -r nginx; useradd -r -g nginx nginx; ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-pcre | tee /tmp/nginx.out -->重定向至文件; make && make install;
二、配置Nginx vi /etc/nginx/nginx.conf
Nginx的代碼是由一個核心和一系列的模塊組成, 核心主要用于提供Web Server的基本功能,以及Web和Mail反向代理的功能;還用于啟用網絡協議,創建必要的運行時環境以及確保不同的模塊之間平滑地進行交互。不過,大多跟協議相關的功能和某應用特有的功能都是由nginx的模塊實現的。這些功能模塊大致可以分為事件模塊、階段性處理器、輸出過濾器、變量處理器、協議、upstream和負載均衡幾個類別,這些共同組成了nginx的http功能。事件模塊主要用于提供OS獨立的(不同操作系統的事件機制有所不同)事件通知機制如kqueue或epoll等。協議模塊則負責實現nginx通過http、tls/ssl、smtp、pop3以及imap與對應的客戶端建立會話。
Nginx的核心模塊為Main和Events,此外還包括標準HTTP模塊、可選HTTP模塊和郵件模塊,其還可以支持諸多第三方模塊。Main用于配置錯誤日志、進程及權限等相關的參數,Events用于配置IO模型,如epoll、kqueue、select或poll等,它們是必備模塊。
Nginx的主配置文件由幾個段組成,這個段通常也被稱為nginx的上下文,每個段的定義格式如下所示。需要注意的是,其每一個指令都必須使用分號(;)結束,否則為語法錯誤。
#main 配置段,無需加什么方括號,這里表明是其他幾個盤配置段的公用的配置,當然其他的配置段也可以自己在配置里重新定義;這樣就叫做上下文#定義用戶和用戶組;user nginx nginx ;#優化性能配置!?。∨ccpu相對,一般是cpu數量-1worker_processes 2; worker_cpu_affinity 01 10;#用于實現cpu綁定即無需切換上下文,優化系統性能;#error_log logs/error.log;#error_log logs/error.log notice;error_log logs/error.log info; pid /var/run/nginx/nginx.pid;#要想禁用error-log則需使用如下命令;#error_log /dev/null crit;#此處為調試功能,暫不開啟;#error_log LOGFILE [debug_core | debug_alloc | debug_mutex | debug_event | debug_http | debug_imap];#優化性能的配置,這里好像只能配置時間;timer_resolution 100ms;#每個進程能打開的最大的句柄數,優化性能的配置worker_rlimit_nofile 200;#每個用戶能發向進程的信號數量,這也是性能優化的一部分;貌似會有問題#worker_rlimit_sigpending 200 ;events { worker_connections 1024; #最大的客戶端數量由上下文決定; #max clients = worker_processes * worker_connections #use auto; #下面這個配置是負載均衡鎖,打開此調度會損耗系統性能; #accept_mutex[0n|off] #lock_file為其鎖文件 #一個worker進程為取得一個鎖真正建立連接的最長等待時間;如果某worker去取鎖時,如果有worker在使用,那么得等待這么久再進行第二次 # 請求,默認是500ms; #accept_mutex_delay #ns ; #multi_accept [on|off]; #是否允許并發建立連接,一次響應多個用戶請求;默認為off; #用于調試、定位問題:只調試Nginx時使用,只讓nginx工作在單進程模式下 #daemon [on|off];提供關閉守護進程模式; #是否讓Nginx運行于后臺,默認為on,調試時默認為off,使得信息直接輸出至控制臺 #master_process on | off 是否以此模式運行,默認為on,調試時可設為off以便追蹤。 # } http {#客戶端類指令:如client_body_buffer_size 128k ; client_header_buffer_size 32k;#large_client_buffer_size 32k;client_max_body_size 8m;#client_header_timeout;#keepalive_timeout;#文件IO類指令:如#aio;#directio;#open_file_cache;#open_file_cache_min_uses;#open_file_cache_valid;#sendfile;#hash類指令:用于定義Nginx為某特定的變量分配多大的內存空間,如#types_hash_bucket_size;#server_names_hash_bucket_size;#variables_hash_bucket_size;#套接字類指令:用于定義Nginx如何處理tcp套接字相關的功能,如tcp_nodelay on;#(用于keepalive功能啟用時);tcp_nopush on;#(用于sendfile啟用時); include 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"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #配置壓縮模塊格式;gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 4;#這里是一個引用配置段,我就不啟用了;#include vh/bbs.yourich.com.cn.conf; log_format main '$remote_addr-$remote_user $time_local "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' '$upstream_addr $upstream_response_time $request_time ';# 配置公用的server段# server{# }# server { listen 80; server_name www.sjf.com; index index.html index.php; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; #server_name_hash_bucket_size;定義一次最多存儲多少主機名 # #charset koi8-r; #access_log logs/host.access.log main;#允許根據用戶請求的URI來匹配指定的各location以進行訪問配置;匹配到時,將被location塊中的配置所處理;#比如:http://www.magedu.com/images/logo.gif# =:精確匹配;# ~:正則表達式模式匹配,匹配時區分字符大小寫# ~*:正則表達式模式匹配,匹配時忽略字符大小寫# ^~: URI前半部分匹配,不檢查正則表達式 location ^~ /admin{ auth_basic "Auth Area"; auth_basic_user_file /etc/nginx/.nginx_passwd; } location ~ .*\.(jpg|jpeg|png|gif\js|css)$ { root /usr/html; access_log off; } location / { root /usr/html; #try_files $uri $uri/ /index.php?$args; index index.html index.htm index.php ; } location ~* \.php$ { # expires -1s; #這一條是可以不寫的; root /usr/html; # try_files $uri =404 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php ; fastcgi_param SCRIPT_FILENAME /usr/html$fastcgi_script_name; include fastcgi_params; #fastcgi_param QUERY_STRING $query_string; #fastcgi_param REQUEST_METHOD $request_method; #fastcgi_param CONTENT_TYPE $content_type; #fastcgi_param CONTENT_LENGTH $content_length; fastcgi_cache off; fastcgi_cache_key $request_uri; fastcgi_cache_valid 200 302 10m; fastcgi_cache_valid 301 1h; fastcgi_cache_valid any 1m; } location ~* ^/(status|ping)$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } location /status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.42.171; deny all; } 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; #fastcgi_param CONTENT_TYPE $content_type; #fastcgi_param CONTENT_LENGTH $content_length; fastcgi_cache off; fastcgi_cache_key $request_uri; fastcgi_cache_valid 200 302 10m; fastcgi_cache_valid 301 1h; fastcgi_cache_valid any 1m; } location ~* ^/(status|ping)$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } location /status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.42.171; deny all; } 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; }
這里我們用數據哭給用戶授權對論壇數據庫的訪問
mysql -uroot -p123 -e 'create database ultrax;' mysql -u root -p123 -e 'grant all on 'root'@'192.168.42.171' identified by '123'; '
這里我們解壓Discuz
這里我們用數據哭給用戶授權對論壇數據庫的訪問
這里我們解壓Discuz
得到這個目錄,然后我們復制所有文件到/usr/html 中
chown -R ngin.nginx /usr/html
然后修改/etc/php-fpm.d/www.conf
將與php連接的用戶和組均改為nginx.
這樣我們打開網站首頁就可以進行訪問了?。?/h6>
接下來我們要實現的就是結合nfs 實現多級LNMP的架構?。?!
原創文章,作者:sjfbjs,如若轉載,請注明出處:http://www.www58058.com/54277