nginx安装教程
墨初 服务器 1041阅读
Nginx是一个高性能的html与反向代理的web服务器,同时也提供了IMAP/POP3/SMTP等服务,现在很多的网站都在使用Nginx。关于Nginx,下面的博文就说一说它在linux服务器上的安装方法。
Nginx安装的方法
# 下载nginx安装包 wget http://nginx.org/download/nginx-1.14.2.tar.gz # 解压源码 tar -zxvf nginx-1.14.2.tar.gz 3、进入解压后的源码目录 cd nginx-1.14.2 # ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/usr/local/src/ModSecurity-nginx # 编辑与安装 make make install
Nginx配置方法
1、创建目录
日志目录 /www/logs/nginx/
证书目录 /usr/local/nginx/ssl/
2、主配置文件
user www www; worker_processes 8; pid /var/run/nginx.pid; worker_rlimit_nofile 65535; events { worker_connections 65535; } http { charset utf-8; include mime.types; default_type application/octet-stream; log_format main escape=json '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$request_time" "$request_body" "$host"'; error_log logs/nginx_error.log error; #proxy_ignore_client_abort on; proxy_buffering off; server_names_hash_bucket_size 128; client_header_buffer_size 128k; large_client_header_buffers 4 128k; client_max_body_size 100m; client_body_buffer_size 1024k; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; sendfile on; tcp_nopush on; keepalive_timeout 65; tcp_nodelay on; fastcgi_intercept_errors on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 4 128k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png; gzip_vary on; server_tokens off; proxy_hide_header X-Powered-By; proxy_hide_header Server; fastcgi_hide_header X-Powered-By; include conf.d/*.conf; }
3、报错设置
error_page 500 502 503 504 /50x.html;
4、子域名
server { listen 80; listen 443 ssl; #域名配置 server_name subdomain.domain.com; #根目录 root /www/domain/public; index index.php index.html; # 没搞明白这里为啥是关闭 ssl off; # 证书 ssl_certificate /usr/local/nginx/ssl/domain.com.pem; ssl_certificate_key /usr/local/nginx/ssl/domain.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; if ($host !~* ^(.*)\.domain\.com$) { return 403; } # enable HSTS #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;preload" always; #if ($scheme = http) { # return 301 https://$host$request_uri; #} if ($time_iso8601 ~ "^(\d{4}-\d{2}-\d{2})") { set $year $1; set $month $2; set $day $3; } access_log /www/logs/nginx/domain_access_$year-$month-$day.log main; error_log /www/logs/nginx/domain_error.log error; # 配置php部分 location / { try_files $uri $uri/ /index.php?$query_string; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } }
Nginx启动与停止
#启动 $ /usr/local/nginx/sbin/nginx #停止 $ /usr/local/nginx/sbin/nginx -s stop #重启 $ /usr/local/nginx/sbin/nginx -s reload
设置开机启动
systemctl enable nginx
以上就是关于nginx配置的教程,各位可以借鉴一下。