首页 > 技术文章 > lemp-----1安装nginx

han1094 2017-02-08 14:25 原文

yum install pcre-devel openssl-devel    #安装环境

groupadd www && useradd -s /sbin/nologin -g www -M www   #建立属于nginx的用户和组

wget http://nginx.org/download/nginx-1.10.3.tar.gz    #下载nginx

tar zvxf nginx-1.10.3.tar.gz     #解压

安装

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module

make

make install

写system文件方便管理

vi /usr/lib/systemd/system/nginx.service

  

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

systemctl daemon-reload   #重新加载

systemctl restart nginx.service #重启

lsof -i:80

systemctl enable nginx.service
lsof -i:80

ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx/nginx.conf

vi /etc/nginx/nginx.conf

 

echo "<h1>hanleizuishuai</h1>" > /web/index.html

chcon -R -t httpd_sys_rw_content_t /web/

systemctl restart nginx.service

systemctl stop firewalld.service
 systemctl disable firewalld.service

 

访问192.168.1.142 测试

 

推荐阅读