美文网首页
centos7下搭建LNMP之Nginx

centos7下搭建LNMP之Nginx

作者: heywork | 来源:发表于2017-06-08 12:59 被阅读0次

    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证书,教程就自己去看吧。

    相关文章

      网友评论

          本文标题:centos7下搭建LNMP之Nginx

          本文链接:https://www.haomeiwen.com/subject/lcozfxtx.html