赞
踩
1、安装所需的依赖
2、下载nginx稳定版
nginx官网下载
http://nginx.org/en/download.html
http://nginx.org/download/
3、编译&安装
# 进入nginx目录,默认安装目录:/usr/local/nginx(进入nginx文件夹,运行configure脚本)
cd /home/nginx/
# 执行命令 (默认会安装在/usr/local/nginx)这里通过configure命令指定安装目录
./configure --prefix=/webnginx
# 执行make命令(要是执行不成功请检查最开始安装的四个有没有安装成功)
# 执行make install命令
make && make install
# 查看编译参数命令
./configure --help | more
4、启动nginx
1.进入nginx下的sbin目录
cd /webnginx/sbin
2.执行启动
./nginx
3.查看nginx是否启动
ps -ef | grep nginx
4.浏览器访问你的IP
1.进入nginx下的sbin目录
cd /webnginx/sbin
2.启动
./nginx
3.关闭
./nginx -s stop
4.重启
./nginx -s reload
- 1.创建nginx.service文件
- vim /usr/lib/systemd/system/nginx.service
-
- 2.nginx.service文件中写入内容
- [Unit]
- Description=nginx web service
- Documentation=http://nginx.org/en/docs/
- After=network.target
-
- [Service]
- Type=forking
- PIDFile=/webnginx/logs/nginx.pid
- ExecStartPre=/webnginx/sbin/nginx -t -c /webnginx/conf/nginx.conf
- ExecStart=/webnginx/sbin/nginx
- ExecReload=/webnginx/sbin/nginx -s reload
- ExecStop=/webnginx/sbin/nginx -s stop
- PrivateTmp=true
-
- [Install]
- WantedBy=default.target
-
-
- 3.改权限
- chmod 755 /usr/lib/systemd/system/nginx.service
-
- 4.文件生效
- systemctl daemon-reload
-
- 5.设置开机自启
- systemctl enable nginx.service
-
- 1.启动
- systemctl start nginx
-
- 2.停止
- systemctl stop nginx
-
- 3.重启
- systemctl restart nginx
-
- 4.重新加载配置文件
- systemctl reload nginx
-
- 5. 查看Nginx状态
- systemctl status nginx
-
- 6.开机自动
- systemctl enable nginx
-
- #user nobody;
- #进程的数量
- worker_processes 1;
- #错误日志:存放路径
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #进程标识符
- #pid logs/nginx.pid;
-
-
- events {
- worker_connections 1024;
- }
-
- #设定http服务器,利用它的反向代理功能提供负载均衡支持
- http {
- include mime.types;
- default_type application/octet-stream;
-
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
-
- #access_log logs/access.log main;
-
- sendfile on;
- #tcp_nopush on;
-
- #超时时间
- #keepalive_timeout 0;
- keepalive_timeout 65;
-
- #gzip on;
-
- #配置虚拟机
- server {
- listen 9990;#监听端口
- server_name localhost;#主机ip
- #请求转发
- location / {
- proxy_pass http://localhost:8001;
-
- }
-
- location /app{
- try_files $uri $uri/ /app/index.html;
- }
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- location / {
- root html;
- index index.html index.htm;
- }
-
- #error_page 404 /404.html;
-
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
-
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
-
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
-
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
-
-
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
-
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
-
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
-
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
-
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。