安装nginx

一、下载
wget http://nginx.org/download/nginx-1.9.15.tar.gz
二、安装
先安装必要的依赖

yum  install pcre-devel openssl openssl-devel cyrus-sasl-md5  zlib zlib-devel
tar zxvf nginx-1.9.15.tar.gz
cd ./nginx-1.9.15

./configure --prefix=/usr/local/nginx   --with-http_ssl_module  --with-http_v2_module  --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module  --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module      --with-debug   --with-file-aio --with-mail --with-mail_ssl_module --with-stream    --with-ld-opt="-Wl,-E"      
--with-http_image_filter_module  --add-module=/home/work/fastdfs-nginx-module-master/src/
make && make install       

三、nginx开机启动
在系统服务目录里创建nginx.service文件

vi /lib/systemd/system/nginx.service

写入以下内容(路径改成自己的)

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

Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

使用以下命令开启

systemctl start nginx.service                 如果服务是开启状态,使用此命令会启动失败。
systemctl enable nginx.service                注意后面不能跟空格

shutdown -r now                                重启系统
systemctl list-units --type=service            查看运行的服务

其他命令

systemctl start nginx.service              #启动nginx服务
systemctl enable nginx.service             #设置开机自启动
systemctl disable nginx.service            #停止开机自启动
systemctl status nginx.service             #查看服务当前状态
systemctl restart nginx.service           #重新启动服务
systemctl list-units --type=service        #查看所有已启动的服务

开启端口

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容