redhat7.4 安装lnmp操作环境-nginx

添加源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

在这里插入图片描述

安装Nginx

sudo yum install -y nginx

在这里插入图片描述
直到出现 Complete!

启动

sudo systemctl start nginx.service

启动后在浏览器上访问,网页出现以下内容说明安装成功。

Nginx常用命令

查看版本:nginx -v

查看nginx安装目录:ps -ef | grep nginx

检查配置文件:nginx -t

启动:systemctl start nginx.service

停止:systemctl stop nginx.service

重启:systemctl restart nginx.service

设置开机自启动:systemctl enable nginx.service

停止开机自启动:systemctl disable nginx.service

查看当前状态:systemctl status nginx.service

查看所有已启动的服务:systemctl list-units --type=service

搭配php 配置多站点

server { 
listen 80; 
server_name example.com; 
root /var/www/example.com; 
location / { 
index index.php index.html index.htm; 
} 
location ~ \.php$ {
 fastcgi_pass 127.0.0.1:9000;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
  include fastcgi_params; 
  } 
  } 
  server { 
  listen 80; 
  server_name test.com; 
  root /var/www/test.com; 
  location / { 
  index index.php index.html index.htm; 
  } 
  location ~ \.php$ { 
  fastcgi_pass 127.0.0.1:9000;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
   include fastcgi_params; 
   } 
   } 
server {
    listen    8000;
    server_name api.com;
    root  project/public/;
    location / {
      index index.php index.html error/index.html;
        try_files $uri $uri/ /index.php?$query_string;
      autoindex off;
        if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;   break;
        }
    }
    location ~ \.php(.*)$ {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
      include    fastcgi_params;
    }
}
server {
    listen       8085;

    server_name  192.168.1.36;

    root /data/wwwroot/fengye_app_api/public/; 

    access_log  /var/log/nginx/fengye_app_api.access.log main;
    error_log  /var/log/nginx/fengye_app_api.error.log info;

  
     location / {
      index index.php index.html error/index.html;
        try_files $uri $uri/ /index.php?$query_string;
        autoindex off;
        if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;   break;
        }
    }


    location ~ \.php(.*)$ {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
      include    fastcgi_params;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


报错: bind() to 0.0.0.0:8085 failed (13: Permission denied)

修改 /etc/selinux/config :SELINUX=enforcing改为SELINUX=disabled 之后重启服务器
还不行
查看http允许访问的端口:
semanage port -l | grep http_port_t

http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

将需要使用的端口8085加入到端口列表中

 semanage port -a -t http_port_t -p tcp 8085
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值