nginx实战问题

2019-01-03
  1. nginx部署完项目提示403

    检查selinux配置,需要禁止selinux。

    检查nginx运行账号是否有权限访问项目目录

    检查index 配置中是否包含项目主页

  2. nginx只允许域名不允许ip

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    server{
    listen 8080;
    server_name nginx.myi-cloud.com;
    root /var/www/html/study;
    location /{
    index index.html;
    }
    }
    server {
    listen 8080 default_server;
    server_name _;
    return 403;

    }

  3. 配置https

    1
    2
    3
    4
    5
    6
    7
    8
    9
    server {
    listen 443 ssl;
    server_name nginx.myi-cloud.com;
    ssl on;
    ssl_certificate /etc/nginx/ssl/nginx.pem;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    ssl_session_cache shared:sslcache:20m;
    ssl_session_timeout 10m;
    }
  4. 配置网页密码认证

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     yum -y install httpd-tools
    htpasswd -c -m .htpasswd habi

    server{
    listen 8080;
    server_name nginx.myi-cloud.com;
    root /var/www/html/study;
    auth_basic "Please input password";
    auth_basic_user_file /etc/nginx/.htpasswd;
    location /{
    index index.html;
    }
    }