当前位置: 首页 > Linux

阿里云centos7.6安装nginx1.14.2

时间:2023-04-06 02:41:47 Linux

添加nginx用户组addnginxuseradd-gnginxnginxdownloadunzipwget"http://nginx.org/download/nginx-1.14.2.tar.gz"tarxzvfnginx-1.14.2.tar.gz#同时下载清理缓存插件wget"http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz"tarxzvfngx_cache_purge-2.3.tar.gz编译安装需要使用root用户cdnginx-1.14.2#ngx_cache_purge-2.3路径在你刚刚解压的路径里./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_v2_module--with-http_ssl_module--with-http_sub_module--with-http_flv_module--with-http_stub_status_module--with-http_gzip_static_module--with-pcre--add-module=/home/flame/software/ngx_cache_purge-2.3make&&makeinstall添加systemctlvim/lib/systemd/system/nginx.service输入如下内容[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx-sreloadExecStop=/usr/local/nginx/sbin/nginx-squitPrivateTmp=true[Install]WantedBy=multi-user.target修改配置文件cd/usr/local/nginx/confmkdirvhostvimnginx.conf输入以下内容#usernobody;worker_processes1;#设置值和CPU核心数一致error_log/usr/local/nginx/logs/nginx_error.logcrit;#日志位置和日志级别别pid/usr/local/nginx/nginx.pid;#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.worker_rlimit_nofile8192;events{useepoll;worker_connections8192;}http{包括mime.types;default_type应用程序/八位字节流;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent"$http_x_forwarded_for';#字符集gb2312;server_names_hash_bucket_size128;client_header_buffer_size32k;large_client_header_buffers432k;client_max_body_size8m;发送文件;tcp_nopush上;keepalive_timeout60;tcp_nodelayon;fastcgi_connect_timeout300;fastcgi_send_timeout300;fastcgi_read_timeout300;fastcgi_buffer_size64k;fastcgi_buffers464k;fastcgi_busy_buffers_size128k;fastcgi_temp_file_write_size128k;gzip上;gzip_min_length1k;gzip_buffers416k;gzip_http_version1.0;gzip_comp_level2;vhost/*.conf;}vimvhost/php.conf输入如下内容root/usr/local/nginx/html;#站点目录位置~\.php${root/home/www/webroot/php;fastcgi_pass127.0.0.1:9080;fastcgi_indexindex.php;包括fastcgi.conf;}location~.*\.(gif|jpg|jpeg|png|bmp|swf|ico)${过期30天;#access_log关闭;}location~.*\.(js|css)?${过期15d;#access_log关闭;}access_log"/usr/local/nginx/logs/php_access.log"主要;error_log"/usr/local/nginx/logs/php_error.log"info;}测试启动nginx/usr/local/nginx/sbin/nginx-tsystemctlstartnginx#或/usr/local/nginx/sbin/nginxcentos7firewallopenport#openport8080firewall-cmd--zone=public--add-port=8080/tcp--permanent#reloadfirewall-cmd--reload#查看状态firewall-cmd--list-all阿里云端口安全组设置安全组说明添加8080端口添加新的【入站方向】规则测试打开xxx.xxx.xxx.xxx:8080如果有【欢迎使用】nginx!]成功