Centos7 下安装nginx 1.13.2,配置WEB服务器运行,并设置开机自行启动服务。
安装nginx
参考教程:CentOS 7 下安装 Nginx
yum install gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
wget -c https://nginx.org/download/nginx-1.13.2.tar.gz tar -zxvf nginx-1.13.2.tar.gz cd nginx-1.13.2 ./configure
make && make install
|
./configure \ --prefix=/usr/local/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --pid-path=/usr/local/nginx/conf/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
|
启动nginx
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s reload ./nginx -s quit
|
查看nginx进程
配置nginx
vi /usr/local/nginx/conf/nginx.conf
|
nginx.conf
配置内容(http{}
内):
gzip on; gzip_http_version 1.1; gzip_comp_level 2;
upstream node { server 127.0.0.1:xxxx; } server { listen 80; server_name localhost; location / { root /var/public_root/www; index index.html index.htm;
proxy_pass_header Server; proxy_set_header Host $http_host; proxy_set_header x-forwarded-for $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://node; } location /assets/ { root /var/public_root/www; } }
|
设置NGINX开机启动
参考教程:Nginx+Center OS 7.2 开机启动设置(转载)
vi /lib/systemd/system/nginx.service
|
nginx.service
内容:
[Unit] Description=nginx 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
|
赋予所有用户权限
chmod a+x /lib/systemd/system/nginx.service
设置开机启动:systemctl enable nginx.service
其他命令:
systemctl start nginx.service
systemctl disable nginx.service
systemctl status nginx.service
systemctl restart nginx.service
systemctl list-units --type=service
图片资源403
开放端口
centos7 打开mysql 3306端口并 设置外部访问
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --zone=public --list-ports
sudo systemctl restart firewalld.service
|
关闭防火墙
外网无法访问时,记得关闭防火墙↓或放开外部访问端口↑
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
|