1、LAMP安裝注意事項php
*注:設置SELinux爲permissive模式 命令行下 setenforce 0 當即生效,重啓失效 修改配置文件後, 重啓apache才能生效 css
2、LNMP安裝
必須開啓 --enbale-fpmhtml
groupadd www useradd -s /sbin/nologin -g www www ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module make && make install 軟鏈接 ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx
修改配置文件支持php
可把 root 改成想要的目錄
打開一下 #nginx
#location ~ \.php$ { # root /home/wwwroot/; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; # } like this: location ~ \.php$ { root /home/wwwroot/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
也能夠把給段配置改成改
*$document_root指 定義的根目錄redis
location ~\.php{ fastcgi_pass unix:/tmp/php-fcgi.sock; //下面解釋 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; }
*fastcgi_pass 裏的 127.0.0.1:9000; 可改成unix:/tmp/php-fcgi.sock;
須要更改 php-fpm.conf 須要添加
group=www
user=www
listen=/tmp/php-fcgi.sock
listen.owner= www
listen.group =wwwapache
還要創建 /tmp/php-fcgi.sock; touch /tmp/php-fcgi.socksession
chown www:www /tmp/php-fcgi.sock 賦予其權限 nginx -s reload php-fpm 重啓
配置文件 :app
server{ listen 8080; server_name 192.168.139.134:8080; index index.html index.htm index.php; root /home/wwwroot/demo; location ~\.php{ fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } *************************************************** #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; #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 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /home/wwwroot/; index index.html index.htm index.php; } #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 /home/wwwroot/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$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; # } #} include vhost/*.conf; }
//nginx 負載均衡 反相代理負載均衡
upstream redis { //redis自定義的 和下面 proxy_pass http://redis;名稱對應 server 192.168.244.129:8080; server 192.168.244.109:8080; #ip_hash;// } server { listen 8787; //主機端口 server_name 192.168.0.123:8787; 主機端口 ip location / { proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://redis; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } }