Linux 安装nginx 1.9.11
需要安装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;
}
}