
离线 TA的专栏
- 打卡等级:即来则安
- 打卡总天数:16
- 打卡月天数:0
- 打卡总奖励:229
- 最近打卡:2024-07-17 00:23:22
|
目录
- 1、安装nginx
- 2、启动nginx服务
- 3、配置文件修改
- 4、重置nginx且重启
- 5、卸载nginx
- 总结
1、安装nginx
2、启动nginx服务
外部浏览器访问默认80端口
3、配置文件修改
- vim /etc/nginx/nginx.conf
复制代码- #user www-data;
- user root; #使用root
- worker_processes auto;
- pid /run/nginx.pid;
- include /etc/nginx/modules-enabled/*.conf;
- events {
- worker_connections 768;
- # multi_accept on;
- }
- http {
- ##
- # Basic Settings
- ##
- sendfile on;
- tcp_nopush on;
- tcp_nodelay on;
- keepalive_timeout 65;
- types_hash_max_size 2048;
- # server_tokens off;
- # server_names_hash_bucket_size 64;
- # server_name_in_redirect off;
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
- ##
- # SSL Settings
- ##
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
- ssl_prefer_server_ciphers on;
- ##
- # Logging Settings
- ##
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log;
- ##
- # Gzip Settings
- ##
- gzip on;
- # gzip_vary on;
- # gzip_proxied any;
- # gzip_comp_level 6;
- # gzip_buffers 16 8k;
- # gzip_http_version 1.1;
- # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
- ##
- # Virtual Host Configs
- ##
- include /etc/nginx/conf.d/*.conf;
- include /etc/nginx/sites-enabled/*;
- server {
- listen 8080; #监听端口
- server_name 172.16.30.70; #当前nginx部署机器地址,或是当前机器的公网地址
- # 全局跨域添加
- #add_header 'Access-Control-Allow-Origin' '*';
- #add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
- #add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,OPTIONS';
- #add_header 'Access-Control-Allow-Headers' 'X-Requested-With';
- location / {
- auth_basic off; #参数off表示不开启HTTP基本认证
- root /root/webwork/dist; #前端项目路径
- index index.html index.htm; #index
- proxy_pass http://172.16.30.70:8085; #后端接口地址(要转发的地址服务)
- # 跨域
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
- add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'X-Requested-With';
-
- ##
- proxy_set_header Host $host:$server_port;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_connect_timeout 300s;
- proxy_send_timeout 300s;
- proxy_read_timeout 300s;
- proxy_http_version 1.1;
- }
- }
- # 转发10.7.57.29:6800到23.91.97.141:399
- server {
- listen 39907;
- server_name 23.91.97.141;
- location / {
- auth_basic off;
- proxy_pass http://10.7.57.29:6800;
- }
- }
- # 负载均衡到10.7.187.21:18001
- server {
- listen 18001;
- server_name 10.7.187.21;
- location / {
- proxy_pass http://destination-address1;
- }
- }
- upstream destination-address1 {
- server 10.7.173.36:18001;
- server 10.7.124.180:18001;
- }
-
- }
- #转发redis端口到39906
- stream {
- server {
- listen 39906;
- proxy_pass 10.7.187.21:6379;
- }
- }
- #mail {
- # # See sample authentication script at:
- # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
- #
- # # auth_http localhost/auth.php;
- # # pop3_capabilities "TOP" "USER";
- # # imap_capabilities "IMAP4rev1" "UIDPLUS";
- #
- # server {
- # listen localhost:110;
- # protocol pop3;
- # proxy on;
- # }
- #
- # server {
- # listen localhost:143;
- # protocol imap;
- # proxy on;
- # }
- #}
复制代码 4、重置nginx且重启
- service nginx reload
- service nginx restart
复制代码 5、卸载nginx
- apt-get remove nginx nginx-common # 卸载删除除了配置文件以外的所有文件。
- apt-get purge nginx nginx-common # 卸载所有东东,包括删除配置文件。
- apt-get autoremove # 在上面命令结束后执行,主要是卸载删除Nginx的不再被使用的依赖包。
- apt-get remove nginx-full nginx-common #卸载删除两个主要的包。
复制代码 总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持晓枫资讯。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
晓枫资讯-科技资讯社区-免责声明
免责声明:以上内容为本网站转自其它媒体,相关信息仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同其观点或证实其内容的真实性。
1、注册用户在本社区发表、转载的任何作品仅代表其个人观点,不代表本社区认同其观点。
2、管理员及版主有权在不事先通知或不经作者准许的情况下删除其在本社区所发表的文章。
3、本社区的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,举报反馈:  进行删除处理。
4、本社区一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、以上声明内容的最终解释权归《晓枫资讯-科技资讯社区》所有。
|