centos7下搭建LNMP之Nginx

1、yum 安装:yum install nginx,对于刚入门的同学提醒一下,下载的时候会提示你:Is this ok [y/d/N]:y

2、启动:service nginx start

chkconfig nginx on

3、下面几个流程一般教程没有,加不加也行:

①、最大WEB 打开文件数:ulimit -SHn 65535

②、检查语法:/usr/sbin/nginx -t

③、打开这个文件:vim /etc/rc.local

④、末尾写入:ulimit -SHn 65535

4、配置nginx配置文件,直接写nginx.conf或分开配置到default.conf都行,我就直接写到一个文件里了

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

worker_connections 1024;

}

http {

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  /var/log/nginx/access.log  main;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 8m;

sendfile            on;

tcp_nopush          on;

tcp_nodelay        on;

keepalive_timeout  65;

types_hash_max_size 2048;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

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;

gzip_vary on;

include            /etc/nginx/mime.types;

default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.

# See http://nginx.org/en/docs/ngx_core_module.html#include

# for more information.

include /etc/nginx/conf.d/*.conf;

server {

listen 80;

server_name 网站域名;

rewrite ^(.*)$  https://$host$1 permanent;

}

server {

listen 443;

server_name 网站域名;

index index.html index.htm index.php;

root 网站路径;

ssl on;

ssl_certificate  证书路径;

ssl_certificate_key  证书路径;

ssl_session_timeout 5m;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_prefer_server_ciphers on;

location / {

root 网站路径;

index index.html index.htm index.php;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

try_files $uri $uri/ /index.php?$query_string;

}

location ~ \.php$ {

if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

}

上面的是配置了SSL证书的文件内容,在阿里云或者腾讯云或者其他都可以申请免费的SSL证书,教程就自己去看吧。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 2,098评论 0 9
  • 1.ngnix介绍 ngnix www服务软件 俄罗斯人开发 开源 性能很高 本身是一款静态WWW软件 静态小文件...
    逗比punk阅读 2,135评论 1 6
  • 1.简介:  Nginx:engine X ,2002年,开源,商业版 http协议:web服务器(类似于ht...
    尛尛大尹阅读 1,903评论 0 3
  • 许心一说,步步高打火机,哪里不会点哪里,妈妈再也不用担心我的学习!哈哈……
    平仙冰俏阅读 282评论 0 0
  • 至于去夜读室的另一个隐情,不想回宿舍而已。现在除了傍晚回来洗澡,23.00-6.20睡觉,其他时间基本不在宿舍。 ...
    叁叁得酒阅读 234评论 0 1