配置静态服务器与nginx的安装与配置
大苹果

配置静态服务器与nginx的安装与配置

centos服务器可用登录远端服务器sshroot@ip#输入密码登入终端执行netstat-tunlp如果显示相关服务的相关情况。则进行下一步,如果提示命令不存在则执行yuminstall-ynet-tools配置静态服务器可以用的服务软件有apache、nginx等,这里以nginx为例。nginx的安装相关准备如下:首先先安装nginx所需的依赖#安装nginx依赖yuminstallzlibzlib-developensslopenssl-develpcre-devel-yyuminstall-ymakegccgcc-c++-y下载nginxnginx下载地址:http://nginx.org/en/download.html我们可以通过wget下载,当然首先要先安装wget#如果没有wget则执行yuminstall-ywgetwgethttp://nginx.org/download/nginx-1.12.2.tar.gz#nginx安装另一个依赖pcre只要解压不需安装wgethttps://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gztar-zxvfpcre-8.40.tar.gz#下载完成后解压tar-zxvfnginx-1.12.2.tar.gzcdnginx-1.12.2./configure\--prefix=/usr/local/nginx\--sbin-path=/usr/local/nginx/sbin/nginx\--conf-path=/usr/local/nginx/conf/nginx.conf\--pid-path=/usr/local/nginx/nginx.pid\--with-http_ssl_module\--with-pcre=\--with-zlib=\--error-log-path=/data/nginx/error/error.log\--http-log-path=/data/nginx/error/http.log\--user=www\--group=www\--lock-path=/var/lock/nginx.lock\--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=../pcre-8.40make&&makeinstall配置首先要创建nginx的执行用户groupaddwwwuseraddwww-gwww-s/sbin/nologin然后进入nginx的配置文件目录cd/usr/local/nginx/conf#修改nginx配置文件vimnginx.confnginx配置文件讲解#执行用户,上面已执行过创建操作userwww;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.types;default_typeapplication/octet-stream;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent""$http_x_forwarded_for"';access_loglogs/access.logmain;server_tokensoff;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;#配置最大请求资源大小client_max_body_size40m;#开启gzip压缩gzipon;server{listen80;#监听端口server_namelocalhost;#配置域名root/usr/local/nginx/html;#资源路径#charsetkoi8-r;access_loglogs/host.access.logmain;#location/{#roothtml;#indexindex.htmlindex.htm;#}#error_page404/404.html;#redirectservererrorpagestothestaticpage/50x.html##错误文件保存目录可以不配置error_page500502503504/50x.html;location=/50x.html{roothtml;}#proxythePHPscriptstoApachelisteningon127.0.0.1:80##location~\.php${#proxy_passhttp://127.0.0.1;#}#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000##location~\.php${#fastcgi_pass127.0.0.1:9000;#fastcgi_indexindex.php;#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;#includefastcgi_params;#}#配置php静态服务不配置location~.*\.(php|php5)?${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;includefastcgi.conf;}#denyaccessto.htaccessfiles,ifApache'sdocumentroot#concurswithnginx'sone##location~/\.ht{#denyall;#}}#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration##server{#listen8000;#listensomename:8080;#server_namesomenamealiasanother.alias;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}#HTTPSserver##server{#listen443ssl;#server_namelocalhost;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cacheshared:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_cipherson;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}#引入vhost目录下的.conf文件includevhost/*.conf;}创建nginx配置存放目录vhost,上面配置文件中已提到mkdir/usr/local/nginx/conf/vhost#创建完成后,我们可以把每个网站的配置文件都放在/usr/local/nginx/conf/vhost#执行以下命令进行配置文件的检测/usr/local/nginx/sbin/nginx-t#如果配置成功则提示#nginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisok#nginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessful#否则提示相应的错误,如果配置无误,则启动nginx服务/usr/local/nginx/sbin/nginx#重启命令为/usr/local/nginx/sbin/nginx-sreload#设置服务器重启自动重启cp/usr/local/nginx/sbin/nginx/etc/init.d/nginxchkconfig--addnginx#查看自动重启项chkconfig--list配置完成后浏览器端访问http://ip或http://你的域名域名需要解析到你的服务器才行note如果不能访问,则要检查是否开放了80端口或者监听是否是80端口,如果是阿里云服务器则检查安全组配置是否正确。

nginx,静态服务器 23374 6年前
共 1 页