Linux 安装nginx 1.9

需要安装zlib、openssl、pcre(默认系统自带)

在这里插入图片描述

创建用户与组

创建用户用于启动nginx进程的用户

groupadd nginx
useradd -r -g nginx nginx

下载-解压-配置-安装(/usr/local)

wget http://nginx.org/download/nginx-1.9.11.tar.gz
tar -zxvf nginx-1.9.11.tar.gz 
cd nginx-1.9.11
./configure --help

配置参数描述:

–with-xxx 代表默认没有打开的功能
–without-xxx 代表默认打开的功能
–prefix=path 代表安装路径
–sbin-path=path sbin路径
–conf-path 配置文件
–pid-path 代表进程号保存文件
–error-log-path错误日志
–lock-path 锁文件
–user ps看到的启动进程用户
–group ps看到的启动进程用户所在组
–with-http_ssl_module
–with-http_flv_module

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --error-log-path=/usr/local/nginx/log/error.log --pid-path=/usr/local/nginx/nginx.pid --lock-path=/usr/local/nginx/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module
make && make install

启动、停止、重启

启动:

sbin/nginx

停止:

sbin/nginx -s quit

重启:

sbin/nginx -s reload

设置开机自动启动

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

加入开机自动启动:

systemctl enable nginx.service

关闭开机自动启动:

systemctl diable nginx.service

如果遇到无权限访问:

systemctl daemon-reexec
systemctl daemon-reload

Tp5访问配置

server {
        listen       80;
        server_name  _;
        location / {
            root   /data/tp5/public;
            index  index.html index.htm index.php;
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=$1  last;
                 break;
                   }

        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php($|/) {
            root           /data/tp5/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值